Install jdk in Ubuntu
First, download JDK from oracle.com. I downloaded the jdk-8u51-linux-x64.tar.gz version. There is an rpm file on the official website. This is an installation version of RedHat. First, I downloaded this version and then installed the rpm In ubuntu, however, when installing the jdk for this rpm, there were many errors and a row of errors were displayed. After that, the tar.gz file was downloaded from the public network. The installation is successful. The installation process is as follows:
The jdk-8u51-linux-x64.tar.gz file we downloaded is in the/home/ranruilong/download folder by default. Here, ranruilong is the directory of my username. In the home directory, we can see our own installation directory, replace it with your own user directory.
Decompress the compressed file and decompress the command.
Sudo tar zxvf./jdk-8u51-linux-x64.tar.gz // here. // do not forget to write, representing the current directory
After decompression, there is a jdk1.8.0 _ 51 in the current directory.
Enter ls in the terminal to see.
Jdk is usually installed in the/opt directory. We will move the decompressed File above to/opt/Java/Jdk.
Enter the command cd/opt on the terminal.
Create a Java Directory: mkdir Java
Go to the Java Directory: cd Java
Create Jdk: mkdir Jdk
After the folder is created, return to the download directory where it starts.
Cd/home/ranruilong/download
Input: mv jdk1.8.0 _ 51/opt/Java/Jdk // to move the extracted file to the Jdk directory.
Go to the Jdk and you will find that the decompressed file has been removed from the original download directory.
The next step is to set environment variables. Because the tar.gz file is compressed when we download the file, we can directly decompress the file, put it in the directory we want, and set the environment variables to use it.
Edit the. bashrc File
Enter vi ~ in the terminal ~ /. Bashrc command to edit the bashrc File
The operation on vi is simple.
Enter I (small I) on the terminal to edit the bashrc file.
Add the following variable at the end of bashrc
Export JAVA_HOME =/opt/Java/jdk1.8.0 _ 51 // The jdk Directory, which is installed by yourself
Export CLASSPATH =$ {JAVA_HOME}/lib:. // here you must +. Path separator:. I didn't add it for the first time, and I couldn't find the main class when running the java file.
Export PATH =$ {JAVA_HOME}/bin: $ PATH
Press the esc key on the keyboard to return to the command mode.
Input: wq to save the file we just modified
Finally, enter source ~ /. Bashrc. You can.
Now let's test whether the installation is successful.
Enter java/javac/java-version on the terminal, and some java-related content will appear. Congratulations, the installation is successful.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.