Why I must use "./eclipse" to run Eclipse?

Asked by Xiao Chen Duan

When I want to run my Eclipse(Java IDE), I must type "./eclipse" in the terminal(after changing to the directory which contains the file named eclipse). However, when I want to run Firefox, I just type"firefox" in the terminal(after changing directory to /usr/bin). Why some times I must type "./XXXX" in the terminal to run the program which named XXXX?

Thanks a lot!

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu firefox Edit question
Assignee:
No assignee Edit question
Solved by:
Murukesh Mohanan
Solved:
Last query:
Last reply:
Revision history for this message
George Standish (george-standish-deactivatedaccount) said :
#1

Using ./ before a command says "from this location".

If eclipse was in your PATH then changing to the directory and using ./eclipse would not be necessary.

You can use the command "echo $PATH" from a terminal and verify that ~/bin is included in your PATH (you may need to create the directory ~/bin, by default it is not there).

Once confirmed and/or created, from inside ~/bin - simply create a symlink to the eclipse binary "ln -s /path/to/eclipse" following this you should be able to simply type eclipse to start it.

Best of luck,
George

Revision history for this message
Xiao Chen Duan (astroboy1113) said :
#2

In Linux, the operating system does not search the current directory for the file named eclipse? By the way, how to differentiate executable file in Linux?

"ln -s /path/to/eclipse" is a command? What's its usage?

Thanks a lot!

Revision history for this message
George Standish (george-standish-deactivatedaccount) said :
#3

Yes, Linux does not search the current directory of executable, this is a security measure to prevent creating "fake" commands from being executed.

From a terminal if you issue the command "ls -l" you will see the permission of files on the left most side in a format similar to
"-rw-r--r--" in this example the file is NOT executable, if we where to see "-rwxr-xr-x" the x represents eXecutable.

The "ln" command is link, which creates a pointer to another file. My original suggestion was to create a pointer in ~/bin which points to the where you have the eclipse executable (the directory that you cd into, then run the command ./eclipse). The "-s" creates a symbolic link.

If you provide the path to eclipse I can give you the full command syntax that would be required.

Hope this clears up my initial answer.

Good luck,
George

Revision history for this message
Xiao Chen Duan (astroboy1113) said :
#4

The file named eclipse(which I use to run Eclipse) is under "/home/doom/develop/eclipse".

Thanks a lot!

Best Regards,
Duan Xiao Chen

Revision history for this message
Xiao Chen Duan (astroboy1113) said :
#5

I typed "ln -s ~/development/eclipse/eclipse" under "~/bin", and then, I type "eclipse" under "~/bin" to run Eclipse, but it said that "command not found". What 's the reason?

Thanks a lot!

Revision history for this message
Best Murukesh Mohanan (murukesh) said :
#6

In the first place, there's no directory named 'bin' in your home folder usually, unless you created it. I think you should either add the eclispe directory to the PATH environment variable, or create a link to eclipse in a directory already present in the PATH variable (in my case, these are /usr/local/sbin, /usr/local/bin, /usr/sbin, /usr/bin, /sbin, /bin, /usr/games). I suggest /usr/local/bin. The command would be:
sudo ln -s ~/develop/eclipse/eclipse /usr/local/bin/
You must use sudo, since the directories present by default in PATH are all owned by root.
I had to do this while using Sagemath.

Revision history for this message
Murukesh Mohanan (murukesh) said :
#7

And to add some directory to the PATH variable, use the command
export PATH=$PATH:/path..to..some..dir
For ~/bin use:
export PATH=$PATH:~/bin
But executing this command in a terminal results in a temporary change only, as long as the terminal is open.To make it permanent,add the line to your .bashrc file (home/doom/.bashrc).
My previous answer would make the command available to all users (assuming others can access and execute the ~/devel/eclipse/eclipse), and this change would make it available only to you.

Revision history for this message
Xiao Chen Duan (astroboy1113) said :
#8

Hi Murukesh,

I'm very grateful for your help. But, I still have some questions.

1. /usr/local/sbin, /usr/local/bin, /usr/sbin, /usr/bin, /sbin, /bin, /usr/games What does these directory used for?
2. Use which command to output the value of PATH environment variable?
3. What is hard link? And what is symbolic link?

Thanks for your help!

Revision history for this message
Murukesh Mohanan (murukesh) said :
#9

Sorry for the late reply. I didn't notice that the status had changed. It would be better if you posted a new question instead of appending to an older one, as this could attract other, perhaps better informed, users. Anyway,

1. These directories contain commands which are available to all users, via the path variable, though owned by root. For example, the games directory contained the executables to the games that are installed. In general, directories with 'bin' (for binary) in them contain executable files,just as 'lib' directories contain the libraries used by these executables and 'doc' directories contain the documentation to them. For a better description, read up on the FIlesystem Hierarchy Standard (http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard).
If you're an ex-Windows user, understand that Linux and Mac OS systems follow a different method. And for that matter, Windows has a path variable too.

2. Output any variable's contents by the echo command. For the PATH variable,the command would be:
echo $PATH
Prefixing $ to a variable name is equivalent to using the value of the variable. Without it, the variable name is just another word.
Other examples would be:
echo $HOME (outputs location of your home directory /home/doom, $HOME is equivalent to ~)
echo $USER (outputs the current user name),
whereas,
echo HOME will simply output
HOME

The echo command copies the input to the output.
3. As for symlinks vs hard links, I am not knowledgeable enough to explain that. You could check out these pages:
http://ubuntuforums.org/showthread.php?t=310834
http://en.wikipedia.org/wiki/Symbolic_link
http://en.wikipedia.org/wiki/Hard_link

Revision history for this message
Xiao Chen Duan (astroboy1113) said :
#10

Hi Murukesh,

first, I think that your suggestion is good. And my problem has been solved.

Thanks a lot!

Best regards,
Duan Xiao Chen

Revision history for this message
Xiao Chen Duan (astroboy1113) said :
#11

Thanks Murukesh Mohanan, that solved my question.