Ubuntu: JAVA_HOME variable shows a blank line on the terminal



Question:

I'm using Ubuntu 16.04 64-bit. I'm logged in to Ubuntu as user1. I installed Oracle JDK version jdk1.8.0_144 to /usr/local/java and set symlinks as

$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_144/jre/bin/java" 1  $ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_144/bin/javac" 1  $ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_144/jre/bin/javaws" 1  $ sudo update-alternatives --set java /usr/local/java/jdk1.8.0_144/jre/bin/java  $ sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_144/bin/javac  $ sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_144/jre/bin/javaws  

Then, I opened .bashrc file with sudo nano ~/.bashrc and added the following lines to the end of the file:

export JAVA_HOME=/usr/local/java/jdk1.8.0_144  export PATH=${JAVA_HOME}/bin:${PATH}  

and saved by typing Ctrl+O.

However, when I type echo $JAVA_HOME, terminal shows a blank line. I closed and opened the .bashrc file and the two lines are still there, so I did save the file properly I think.


Solution:1

The ~/.bashrc file is read once every time a new interactive non-login shell is started. In other words, every time you open a new terminal or just run bash in an already opened terminal. So any changes you have made there won't take effect until you open a new terminal to start a new bash session.

Alternatively, you can source the file in your current session with:

. ~/.bashrc  

That said, never open files with sudo unless necessary and it is never necessary for ~/.bashrc. Make sure the file still belongs to your user (ls -l ~/.bashrc), change ownership if needed (chown swdon:swdon ~/.bashrc) and get into the habit of never using sudo unless you know it is necessary.


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