Ubuntu: How to set JAVA PATH in Ubuntu 12.04?



Question:

So java -version give path not found. I have tried the following: Edit:

  • ~/.bashrc
  • ~/.profile
  • /etc/environment

bash.bashrc files and add to them the following:

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

In addition, I also manually added the java bin directory to PATH.

PATH="/usr/lib/jvm/jre1.7.0_15/bin:/usr/lib/jvm/jdk1.7.0_15/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/games"  

I have restarted my computer several times but I still get

bash: /usr/local/bin/java: No such file or directory  


Solution:1

Try:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jre1.7.0_15/bin/java -1  sudo update-alternatives --config java  

See if that works.

Read more about it at man update-alternatives


Solution:2

Follow these steps:

  • Create a new file called .bash_profile in your home directory:

    vi .bash_profile  
  • Insert the following lines:

    #! /bin/bash  clear    JAVA_HOME=/home/anuradha/installs/jdk1.7.0_02  PATH=$PATH:$HOME/bin:$JAVA_HOME/bin  JRE_HOME=/home/anuradha/installs/jdk1.7.0_02  PATH=$PATH:$HOME/bin:$JRE_HOME/bin  export JAVA_HOME  export JRE_HOME  export PATH  
  • Source the .bash_profile.

  • Check the java version by running java -version.

Note: for the Ubuntu 12.04 64-bit version you need the JDK 64-bit environment.


Solution:3

you might double check if your JDK is x84 or x64. If the version is a wrong one, ubuntu then cannot read it and it will tells you "No such file or directory"


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »