• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set classpath for java in Linux

 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone say me how to set classpath for java in Linux.
Like in windows, we will go to my computer --> properties(right click) ---> adavnced tab --> Environment variable and setting the classpath.

In Linux how we will be setting?
 
Maneesh Godbole
Saloon Keeper
Posts: 11096
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before that how can i set path for java?
 
Maneesh Godbole
Saloon Keeper
Posts: 11096
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which Linux distribution are you using? Different Linux distro's have different preferred ways for installing Java. Google for "<your distro name> Java".

On Ubuntu, the best way to install Sun JDK 6, which will automatically set up your path correctly, is entering the command:
sudo apt-get install sun-java6-jdk
 
Samir Kureshi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try like this....
export CLASSPATH=/local/home/soft/bea81sp6/jdk142_11


hope would help

Thanks,
Samir
 
Campbell Ritchie
Sheriff
Pie
Posts: 49793
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samir Kureshi wrote:try like this....
export CLASSPATH=/local/home/soft/bea81sp6/jdk142_11
No, that won't help at all. That sets a CLASSPATH to a value which is unnecessary and will lose you access to your local files. It is also specific you your computer, and appears to have some errors, eg missing out .s.

You should never set a permanent CLASSPATH if you can possibly help it. You should use the -cp flags on the "java" and "javac" tools, or put it in the manifest file. For the java and javac tools, look here, then look at the links on the right.
 
Pouya Arvandian
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using Ubuntu:

open terminal: gedit .bashrc

then append the following to the bottom of the file:

export JAVA_HOME=/<path to jdk>
export PATH=$JAVA_HOME/bin:$PATH


this worked perfectly for me after I downloaded and compiled jdk binaries from sun website. Hope it helps you too.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49793
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

There is a better way to install Java on a Debian-based Linux installation, which includes Ubuntu: Jesper Young told us here to use sudo apt-get install sun-java6-jdk which sets the PATH automatically. There is a similar instruction to update it.
An rpm-based Linux installation (eg Suse, Fedora) can use a similar instruction with the rpm tool.

The instructions to use export PATH in the .bashrc file should work for any "bash" terminal; Ubuntu and OpenSUSE and Fedora usually use "bash". You can probably find out which terminal you are using by giving a nonsense instruction to the terminal
campbell@linux-747u:~> which bash
/bin/bash
campbell@linux-747u:~> oeirhglkcjxnvgiud
bash: oeirhglkcjxnvgiud: command not found
campbell@linux-747u:~>
And the name of the shell program appears as part of the error message
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic