Ubuntu – How to run NetBeans from the terminal

command linenetbeans

I have installed a JDK + NetBeans bundle from the downloaded .sh file.

Now I have the NetBeans shortcut on my desktop but I can't run NetBeans from the terminal.

When I run:

sudo dpkg --get-selections

NetBeans is not on the list and also I can't find it in the Ubuntu Software Center.

  • How do I run it from the terminal and how do I find it in the system?

  • When I installed Emacs using apt-get it appeared in the main menu and I could launch it from the terminal straight away. How do these two installations differ?

Best Answer

dpkg is a debian package manager, since you have installed Nebeans by a (presumably local) script, it will not be listed in dpkg -l.

Retrieve an application's command from it's desktop file:

When you have an application installed of which you don't know the command, but you do have a desktop file, you can read it from the desktop file's content. The link you have on your desktop is a desktop file. Look for a line, starting with "Exec=". What comes after that string is the command you are looking for.

Make the application available in Dash:

Normally, applications install a desktop file in /usr/share/applications (like emacs does). If a desktop file is located in either that location or in ~/.local/share/applications, it appears in Dash automatically, so if you copy the desktop file into ~/.local/share/applications, it will appear in Dash after next log in.

Open an application by (only) it's binary file name (or not):

Netbeans did not open on the command netbeans because the shell does not know the path to your binary file. If binary files are located in /usr/bin (the default path to application's binary files) they will open right away, without the path-prefix. That is the case for example with emacs.

If an application does not install its binary file in /usr/bin, there are three possibilities; either the application's desktop file's execute line includes the path to the file, as you can see for example in the execute line of the file-explorer indicator's desktop file: /opt/indicator-file-explorer/bin/indicator-file-explorer, or the path to the binary file is added to $PATH (/etc/environment), so the shell will search for binary files in that directory too, or the application installs a link to the binary file in /usr/bin. All three options do occur, no matter the way an application is installed.

If you installed your application locally, it would be a bad idea to (try to-) create a link to the application's binary file from a global directory, such as /usr/bin; other users would be stuck with a dead link, because they have no valid permissions in your home directory. Therefore, the easyest way is to create a local bin directory (~/bin) and create a link to the local binary file from that directory (ln -sf). That way you can run your locally installed Netbeans by the single command netbeans.

Related Question