I just installed JDK in Ubuntu with sudo apt-get install openjdk-6-jdk command, after the installation where's the Java bin directory located? And how can I set the environment path for that directory? I have little experience with Ubuntu, can anyone give some advice or suggest any good website for reference?

share|improve this question

11 Answers 11

up vote 86 down vote accepted

set environment variables as follows

Edit the system Path file /etc/profile

sudo gedit /etc/profile

Add following lines in end

JAVA_HOME=/usr/lib/jvm/jdk1.7.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

Then Log out and Log in ubuntu for setting up the paths..

for reference http://javaandme.com

share|improve this answer
3  
why export JRE_HOME? – whossname Jan 28 '17 at 8:37
    
Editing .bashrc with those lines worked for me – Genarito Nov 12 '17 at 16:59
    
It didn't work for me and the previous version remained as default. I changed the order of the path to export PATH=${JAVA_HOME}/bin:${PATH} and the version got updated. I think left to right priority works here. – Ridhuvarshan Dec 6 '17 at 9:00

Let me Simplify , first download JDK from Oracle Website : Link

2] Then Extract it

3] Create a folder (jvm) in /usr/lib/ i.e /usr/lib/jvm

4] move the extracted folder from the jdk to /usr/lib/jvm/

*Note : use terminal , sudo , mv command i.e. sudo mv

5] Create a .sh file at /etc/profile.d/ eg: /etc/profile.d/myenvvar.sh

6] In the .sh file type

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0

export PATH=$PATH:$JAVA_HOME/bin

*Note : use terminal , gedit and sudo eg: sudo gedit myenvvar.sh

7] Turn Off the Computer, after all these steps and Restart it

8]Open Terminal , and type

java -version

9] Check the output , then type

echo $JAVA_HOME

10] Check the output and be happy :)

share|improve this answer
  • Open terminal (Ctrl+Alt+t)
  • Type

    sudo gedit .bashrc 
    
  • Enter password of ubuntu user
  • Go to last line of the file
  • Type below code in new line

    export JAVA_HOME=enter_java_path_here
    export PATH=$JAVA_HOME/bin:$PATH
    eg: export JAVA_HOME=/home/pranav/jdk1.8.0_131
        export PATH=$JAVA_HOME/bin:$PATH
    
  • Save the file
  • Type

    source .bashrc
    

    in terminal

  • Done
share|improve this answer

if you have intalled only openJDK, the you should update your links, because you can have some OpenJDK intallation.

sudo update-alternatives --config java

after this

$gedit ~/.bashrc

add the following line in the file

JAVA_HOME=/usr/lib/jvm/YOUR_JAVA_VERSION export PATH=$PATH:$JAVA_HOME/bin export JAVA_HOME

you can get you java version with

java -version
share|improve this answer

To set up system wide scope you need to use the

/etc/environment file sudo gedit /etc/environment

is the location where you can define any environment variable. It can be visible in the whole system scope. After variable is defined system need to be restarted.

EXAMPLE :

sudo gedit /etc/environment

Add like following :

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
JAVA_HOME="/opt/jdk1.6.0_45/"

Here is the site you can find more : http://peesquare.com/blogs/environment-variable-setup-on-ubuntu/

share|improve this answer
    
link not working – Killer Sep 12 '17 at 11:35

Installation of Oracle Java:

  1. Donwload the tarball(.tar file) from Oracle website
  2. unzip it by sudo tar -xvpzf fileName -C /installation_folder_name
  3. change the files permission and ownership
  4. add the following two lines in /etc/profile

export JAVA_HOME=/home/abu/Java/jdk1.8.0_45/ export PATH=$JAVA_HOME/bin:$PATH

  1. restart the machine and check by java -version and javac -version
share|improve this answer

To Set JAVA_HOME / PATH for a single user, Login to your account and open .bash_profile file

$ vi ~/.bash_profile

Set JAVA_HOME as follows using syntax export JAVA_HOME=<path-to-java>. If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:

export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java

Set PATH as follows:

export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

Feel free to replace /usr/java/jdk1.5.0_07 as per your setup. Save and close the file. Just logout and login back to see new changes. Alternatively, type the following command to activate the new path settings immediately:

$ source ~/.bash_profile

OR

$ . ~/.bash_profile

Verify new settings:

$ echo $JAVA_HOME
$ echo $PATH

Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:

$ which java

Please note that the file ~/.bashrc is similar, with the exception that ~/.bash_profile runs only for Bash login shells and .bashrc runs for every new Bash shell.

To Set JAVA_HOME / PATH for all user, You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users:

# vi /etc/profile

Next setup PATH / JAVA_PATH variables as follows:

export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

Save and close the file. Once again you need to type the following command to activate the path settings immediately:

# source /etc/profile

OR

# . /etc/profile
share|improve this answer

open jdk once installed resides generally in your /usr/lib/java-6-openjdk As usual you would need to set the JAVA_HOME, calsspath and Path In ubuntu 11.04 there is a environment file available in /etc where you need to set all the three paths . And then you would need to restart your system for the changes to take effect..

Here is a site to help you around http://aliolci.blogspot.com/2011/05/ubuntu-1104-set-new-environment.html

share|improve this answer

Ubuntu installs openjdk6 to /usr/lib/jvm/java-6-openjdk path. So you will have the bin in /usr/lib/jvm/java-6-openjdk/bin. Usually the classpath is automatically set for the java & related executables.

share|improve this answer

Java is typically installed in /usr/java locate the version you have and then do the following:

assuming you are using bash (if you are just starting off, i recommend bash over other shells) you can simply type in bash to start it.

edit your ~/.bashrc file and add the paths as follows:

for eg. vi ~/.bashrc

insert following lines:

export JAVA_HOME=/usr/java/<your version of java>
export PATH=${PATH}:${JAVA_HOME}/bin

after you save the changes, exit and restart your bash or just type in bash to start a new shell

type in export to ensure paths are right

type in java -version to ensure java is accessible

share|improve this answer
    
perfect! thank you. NB: You might want to remove the default openJDK from your system as it appears first in the global path. So after the above script is loaded, you will only pic-up "javac" not java, because of the default openjk-jre. ~sudo apt-get remove openjdk-*~ – kholofelo Maloma Oct 26 '15 at 9:25

It should put java in your path, probably in /usr/bin/java. The easiest way to find it is to open a term and type "which java".

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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