5

System utilities such as ls don't need to have the full path typed before executing them. However, to execute Netbeans, I have to type /home/chris/netbeans-7.0.1/bin/netbeans. How can I make it so that I only have to type netbeans?

Casebash
  • 5,789

3 Answers3

8

An easy way is to place a link in /usr/local/bin:

sudo ln -s -T /home/chris/netbeans-7.0.1/bin/netbeans /usr/local/bin/netbeans

after that you can execute netbeans with:

netbeans &
Michael K
  • 13,888
  • What does the -T do? man says it treats the link name as a normal file - but as opposed to what? – Casebash Feb 16 '12 at 07:21
  • @Casebash: in case the path /usr/local/bin/netbeans already exists and is a directory, without -T would create a the link inside the given directory with the same base name as the linked file. With the -T in such a situation it should give an error. – enzotib Feb 16 '12 at 08:02
  • 1
    Yes, if /usr/local/bin/netbeans already exists you should give the link another name. then you have to invoke the other name as command for starting netbeans. – Michael K Feb 16 '12 at 08:12
  • I'd put the symlink in ~/bin instead; since the executable is located in the homedir. mkdir -p ~/bin && ln -s ~/netbeans-7.0.1/bin/netbeans ~/bin. If ~/bin exists, it will be added to your PATH. This happens during login though, so if ~/bin did not already exist, you need to log out and back in for the new command to be available. – geirha Feb 20 '12 at 06:19
4

You can add an alias

Open Terminal Ctrl+Alt+T

nano ~/.bashrc

write this at the bottom of the file:

alias netbeans='/home/chris/netbeans-7.0.1/bin/netbeans'

Ctrl + x

Y

Enter

The netbeans word is the command you will use to start the program, you can change it to whatever you need. Inside the quotes is the command you want to run when netbeans alias is called.

In order this command to be active you have to re-open the Terminal, or type

. ~/.bashrc
-1
  1. go to the program directory.
  2. open the terminal using ctrl+alt+T.
  3. Drag and drop the program file to the terminal windows.
  4. Hit enter on the terminal windows.
  • or simply create a dektop shortcut :D – Chathura Widanage Feb 16 '12 at 07:14
  • If someone is trying to avoid typing in the path to his program, is going to the program directory in the file manager, and then doing all the things you describe, going to be better? – Chan-Ho Suh Feb 16 '12 at 07:18
  • that's why I told to create a desktop shortcut... desktop shortcut does the same thing in terminal. Then he can take the advantage of seeing program errors in terminal without typing the full path!! – Chathura Widanage Feb 16 '12 at 07:21