1

When installing packages on Ubuntu with the apt-get command, this will ensure that in the future, you can use a variable in the terminal, which will execute a binary file.

If you manually download the source, for instance of the Java JDK, this is not so.

I can't do javac helloworld.java
I have to do /usr/java/jdk1.6.0_21/bin/javac helloworld.java

My question is: is it enough simply to set an alias, or is there more that must be done?

3 Answers 3

2

Whether or not an alias is enough will depend a lot on the program in question and how you use it. If you are the only user on your machine using the program, and you always call it from an interactive console, and never use it inside scripts, then an alias might be sufficient (unless you notice things not working right).

But if you want to use the command in scripts, or even put launchers to it (in the GNOME menu or gnome-panel or in a dock, etc.), then it'll be more convenient to do something else.

Your other options are to 1) define a symbolic link, from, e.g., /usr/local/bin

cd /usr/local/bin
sudo ln -s /usr/java/jdk1.6.0_21/bin/javac javac

Then, javac helloworld.java should work.

Or 2), modify your $PATH environmental variable to include the directory in question, e.g., in your .bashrc or .profile, etc., put:

export PATH=$PATH:/usr/java/jdk1.6.0_21/bin

And then all the executables in that folder can be called directly.

1

update-java-alternatives is the tool to use to set the Java JVM to be used.

0

I don't know what setting an alias will do, but as an alternative, you can add the following line into your .bashrc

export PATH="$PATH:/usr/java/jdk1.6.0_21/bin/"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .