I've done java development before but generally on windows (but I'm by no means an expert).

I just want to set my CLASSPATH. When I run:


(Is that right)? I get a empty line. So, it appears to me that my computer does not have a "Classpath" setup. What is the best practice to setup the classpath in Ubuntu (and linux in general)?

I'm using the default java for Ubuntu which should be OpenJDK. Not sure it's important, but I want to use Rhino (http://en.wikipedia.org/wiki/Rhino_(JavaScript_engine)) Note: I've been able to install Rhino via the package manager. There is both documentation and rhnio packages. Then, the commands are js and rhino-debugger


I'm not a Java programmer, so I don't know the correct value for CLASSPATH. But, you seem to. You can add it to ~/.bashrc like so:


The change will take effect globally the next time you log in. However, it will take effect immediately in new shells.

Additionally, if you want to set it for just one particular command, do this:

CLASSPATH=/something command-here arg1 arg2

A third way would be to create a wrapper script, which would be appropriate if you needed to set multiple variables or if you needed to determine appropriate values programmatically:

export CLASSPATH=/something
export ANOTHER_ENV_Variable=foo

exec your_fancy_program "$@"
  • You are right, this would work but I guess what I'm after is what is the standard way to set the classpath. I think, in fact, there are several ways to set environment variables in Linux. This is probably the "problem" I face. What I seek is the "standard" way to do this, de facto or otherwise... – Frank V Dec 22 '11 at 22:43
  • @FrankV: See my edit above. There's no such thing as a single "standard" way to set environment variables in Linux. I've posted the three most common ways. You should choose the method that makes the most sense for your situation. A single "standard" would be too limiting and not useful. – Scott Severance Dec 23 '11 at 8:53
  • 2
    To set the classpath, you can also use the -cp option, e.g. java -cp /path/to/class/path name – Lekensteyn Dec 23 '11 at 11:09
  • +1 on not using env vars, but rather using the command-line options. For more context, see my answer here on the same subject: askubuntu.com/questions/186693/… – michael Sep 29 '12 at 8:25

that's what happened with me.. i left empty spaces while typing.. it fixed when i removed spaces.

1) if you want to set classpath permanently then 1) find out where java is installed.. you may use " whereis java " openjdk-7/6 is in /usr/lib/jvm/.....

2) we need to set up CLASSPATH in /etc/environment

  sudo gedit /etc/environment

3) add the following likes .. ( DONT LEAVE ANY SPACES WHILE TYPING)(customize according to your java version and installation) (this home path is for open jdk 7)


   export JAVA_HOME


    export CLASSPATH

separate directory by ":"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.