Detailed steps to install jdk under Linux system (two methods in total)

the first method

The jdk can be installed with just one command:

  1. yum install java-1.8.0-openjdk* -y  
yum install java-1.8.0-openjdk* -y
After executing this command, it can be used directly without configuration.

The second method

0. Download jdk8

Login URL: http://www.Oracle.com/technetwork/Java/javase/downloads/jdk8-downloads-2133151.html Select the corresponding jdk version to download. (You can share it to linux through a folder after the download is complete under Windows )

installation steps

1. Log in to Linux and switch to root user

su root to obtain root user permissions, the current working directory remains unchanged (requires root password)
or
sudo -i does not require root password to switch directly to root (requires current user password)

2. Create a java installation directory in the usr directory

cd /usr //Enter the usr directory


mkdir java //Create java directory

3. Copy jdk-8u60-linux-x64.tar.gz to the java directory

cp /mnt/hgfs/linux/jdk-8u60-linux-x64.tar.gz /usr/java/

4. Unzip the jdk to the current directory

tar -zxvf jdk-8u60-linux-x64.tar.gz

get the folder jdk1.8.0_60

5. After installation, create a link for him to save directory length

(I didn't use this step)
ln -s /usr/java/jdk1.8.0_60/ /usr/jdk

6. Edit the configuration file and configure environment variables

vim /etc/profile
add the following: JAVA_HOME is based on the actual directory

JAVA_HOME=/home/software/jdk1.7

PATH=$JAVA_HOME/bin:$PATH

CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export JAVA_HOME PATH CLASSPATH


7. Make the environment variable take effect immediately
: source /etc/profile

sudo shutdown -r now

8. Check the installation

[root@bogon jdk]# java -version
openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-b16)
OpenJDK 64-Bit Server VM (build 25.141-b16, mixed mode)


[root@bogon jdk]# javac -version
javac 1.8.0_141

Possible error messages:

bash: ./java: cannot execute binary file

The reason for this error may be that a 64-bit jdk is installed on a 32-bit operating system
. Check whether the jdk version and the Linux version have the same number of digits.
Check whether the Ubuntu you installed is 32-bit or 64-bit system:
sudo uname --m
i686 //Indicates that it is 32-bit
x86_64 // Indicates that it is 64-bit

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325753466&siteId=291194637