Download the Java Development Kit jdk
The download address of jdk is: http://www.oracle.com/technetwork/java/javase/downloads/index.html
. Click the JDK Download
link in the red box.
On the download page, select the corresponding jdk version according to your own system. Here, take the Ubuntu 20.04 LTS (64bits) system as an example, select the compression type jdk-14.0.1_linux-x64_bin.tar.gz
to download.
installation steps
Move the downloaded jdk to desktop
, and then install it according to the following steps:
cd desktop#Locate the directory where the jdk compressed package is located
sudo cp /home/ym/desktop/jdk-14.0.1_linux-x64_bin.tar.gz /opt #Copy jdk to the specified jdk installation directory
cd /opt #Navigate to the specified jdk installation directory
sudo tar -xzvf jdk-14.0.1_linux-x64_bin.tar.gz #Unzip jdk, get the folder jdk-14.0.1
sudo rm jdk-14.0.1_linux-x64_bin.tar.gz #At this time the jdk compression package is useless, delete it
At this point, the installation of jdk has been half completed, the next step is to configure jdk, the configuration steps are as follows:
# Open the system-level configuration file profile
sudo vi /etc/profile
# Add the following configuration content at the end of the file
JAVA_HOME=/opt/jdk-14.0.1 #Configuration content
CLASSPATH=.
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
# Make the modified configuration take effect
source /etc/profilec
Enter the following commands to view or create or update environment variables:
# View the value of environment variables
echo $JAVA_HOME
echo $CLASSPATH
echo $PATH
Test whether the jdk is installed successfully
Open a terminal;
Type: java -version, javac -version
these two commands, if the following version information about Java and Java compiler appears, it means that the jdk has been installed successfully, and that the system environment variables have been configured successfully.
The first Java program
Code listing: HelloWorld.java
publicclassHelloWorld{//The entry method of the Java program, the program will start to execute publicstaticvoidmain from here(String[] args){//Print a statement to the console
System.out.println("Hello World");}}
Steps to edit, compile and run HelloWorld.java program:
Uninstall
cd /opt #Enter the jdk installation directory
sudo rm -rf jdk-14.0.1 #Uninstall jdk
Recommended Posts