Verify that it has been correctly added to the end of the file: tail -3 ~/.bashrc echo "export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64" > ~/.bashrc Change the command below to use the correct path as displayed by your system in. Next, use the echo command to append the export command you used at the beginning of this section. If you do not want that and take a simple copy-paste approach, use the following commands:īack up your bashrc file (in case you mess it, you can get it back): cp ~/.bashrc ~/.bashrc.bak You can use the Nano editor for editing files in the Linux terminal. To set JAVA_HOME variable ‘permanently’, you should add it to the bashrc file in your home directory. If you close the terminal or start a new session, it will be empty again. The JAVA_HOME variable you just declared is temporary. Try to run your program or project in the SAME TERMINAL and see if it works. Now that you have got the location, use it to set the JAVA_HOME environment variable: export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/bin/javaĬheck the value of JAVA_HOME directory: echo $JAVA_HOME You know, you can copy paste in the Ubuntu terminal. Copy the correct path you got from the above command in your system.
In my example, the location of the executable file is /usr/lib/jvm/java-11-openjdk-amd64. Sed is then used to replace /bin/javac by nothing and thus removing it altogether. This is called command substitution and it replaces the command with its output. The readlink command follows a symbolic link. And when you find a path like /usr/lib/jvm/java-11-openjdk-amd64/bin/javac, you remove the /bin/javac from it to get something like /usr/lib/jvm/java-11-openjdk-amd64Īn easier method is to follow the symbolic link and get to the actual executable file directly using this command: readlink -f `which javac` | sed "s:/bin/javac::"