Poornima
Poornima

Reputation: 13

how to set path in terminal on ubuntu for java?

I have recently installed ubuntu and want to start compiling programs in the terminal. What is the command to set the path for java in ubuntu terminal? I tried "cd path" but it did not work. Could anyone please tell me the right command?

Upvotes: 0

Views: 1984

Answers (3)

sachingupta
sachingupta

Reputation: 739

first of all if you have not installed java you need to execute the command

$ sudo apt-get install openjdk-7-jdk

if it does not work then first execute

$ sudo apt-get update

and the execute the above command

and the do

$ sudo vi /etc/profile

and at the last line of the file add JAVA_HOME={path to java home} PATH=$JAVA_HOME/bin:$PATH

and do $ . /etc/profile

and now you are good to go to see the effect type java -version

Upvotes: 2

ajay.patel
ajay.patel

Reputation: 1967

Try export command.

Check in which location jdk is installed ( in ubuntu, its mostly in /usr/java/(javaVersion))

update the path variable using export:

export PATH=$PATH:/usr/java/(javaVersion)/bin 

Upvotes: 0

Tony
Tony

Reputation: 6148

Actually, you can avoid set the path by following phase:

First you can add ppa:

$ sudo add-apt-repository ppa:webupd8team/java

Then update:

$ sudo apt-get update

Then install it:

$ sudo apt-get install oracle-java8-installer

Finally, check it using the following command:

$ java -version

Result:

java version "1.8.0_05"

Java(TM) SE Runtime Environment (build 1.8.0_05-b13)

Java HotSpot(TM) Server VM (build 25.5-b02, mixed mode)

Upvotes: 0

Related Questions