New machine configuration-install JDK and Idea development environment under Ubuntu

Java is programming voice; JRE is the running environment of Java programs, which means that if you do not develop yourself, you only need to run a program written in Java, you need JRE; JDK is the development environment of Java, if you want to write programs in Java It is necessary to use this package. Generally, the JDK contains the JRE without downloading the JRE separately. The so-called configuration Java development environment is to install the JDK and the corresponding integrated development environment such as IDEA.

Install JDK

First, use the Java command to test whether the machine already has a Java environment. My machine is a new machine, so I can't find the instruction:
Java -version

command java not found

There are many installation methods. The pit I stepped on was directly under the apt-install command, but I forgot to configure environment variables for Java. After using apt to automatically download and install, I can't find the path, wasting a lot of time. It is still recommended to use the official website to download, so the default is in the downloads folder, and the environment variables will be clearer after decompressing to the specified location.

Method 1: apt-install instruction

sudo apt install default jre

The latest version is downloaded by default. Here the default parameter can be selected by the JDK version. During the
installation process, select y to automatically download and install,
and then execute the Java-versioninstruction to return to the Java environment.

openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1, mixed mode, sharing)

Environment variables

Then is to configure environment variables for Java. This is because if the environment variables are not matched, Java-related instructions can only be used in the installation directory, that is to say, your source code must be together with the installation directory, and then each time you execute cd to that directory, run javac and other instructions. Obviously, what we want is that the source code is stored in any specified location, and javac is executed at any time in the terminal, so it must be equipped with environment variables. In fact, I think it is to tell the terminal to go directly to the path every time it executes javac and other instructions. It seems to be used directly.

To configure environment variables, first find the installation path of jdk.
The installation path using the above method is:

usr/lib/jvm/openjdkxxx

Found the javac file in the bin directory of this path, so it is the installation path of the JDK. Here to add the default address installed with apt-get:

Shared document: / usr / share
executable file: / usr / bin
configuration file: / etc
target file, static database: / usr / lib

The format for configuring environment variables is generally to add four paths to / etc / profile:

#set Java environment
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64	
export JRE_HOME=/$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH 
export PATH=$AVA_HOME/bin:$JRE_HOME/bin:$PATH 

However, I found that there is no JRE folder under the JDK installation path, which shows that this general format does not apply to my environment. Looking for information, I found that "jre has been automatically integrated in the latest version of jdk. So in the environment variable configuration of jdk, the JRE_HOME and JAVA_HOME values ​​are the same."

In addition, because there are some sentences in the general format that I can't fully understand, so I checked the relevant information of the environment variables. The explanation for the above is:

  • JAVA_HOME is the absolute path of the executable file, it is necessary to configure the environment variables
  • JRE_HOME is relative to the absolute path of the executable file of the JRE package. The new version of the JDK should integrate this part of the content into the JDK. In theory, I feel that this sentence can be omitted
  • PATH is the system path, which is to tell the system where you want to execute the program. For Java, you usually need to add the bin directory of the JDK into the PATH, so that you can use the executable program under bin in any directory, Such as javac.exe, java.exe, etc. This sentence is the core of configuring environment variables
  • CLASSPATH, as the name suggests, is the path of the CLASS file. It tells the Java environment where to find the packages needed to execute the Java program. Because these packages are mostly in the lib folder, you will also find the existence of the Lib folder in the configuration statement. "However, in versions after JDK1.5, you can run the program normally without setting the classpath environment variable." Therefore, this sentence is not necessary.

To sum up, in fact, the latest version of the JDK environment variable with JAVA_HOME and PATH is enough.

Note that my terminal is zsh, and zsh does not go directly to / etc / profile. So you can choose to add the contents of the above environment variable settings to the .zshrc file. Restart the terminal and execute

echo $JAVA_HOME

The statement will get the location of the JDK

In addition, theoretically write the environment variables in / etc / profile, and then write the last line
source /etc/profile
in .zshrc should have the same effect in zsh, which is equivalent to automatically walking etc / profile in the zsh configuration but doing so After you use echo, you cannot return to the JDK path

At this point, the installation and configuration of the JDK environment is complete, you can type java or javac instructions on the terminal, and the printed mannul of these two instructions should indicate that the configuration is successful

Method two: official website compressed package

Reference:
https://blog.csdn.net/badder2/article/details/89460370?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

Note that if it is a zsh environment variable configuration, please refer to method one

Install Intellij Idea development environment

Go to the official website to download the enterprise version or community-run compressed package (.tar.gz). The enterprise version pays, and you can find a way to solve it. The activation code is generally exclusive to edu. If you have an edu mailbox, you can try it for free for one year. You can also download the community office for free.
The content downloaded with a browser is generally in the Downloads folder by default. You can go to the download directory in the terminal cd and decompress it with the tar command. The default decompression path is also the current download folder:

tar xvf ideaxxx包名

Then enter the unzipped folder, where the idea.sh file is in the bin directory, which is the software startup script.
The terminal ./idea.shcan execute Idea to run Idea
all the way. Follow the installation wizard.
Ubuntu will create a UI for Idea in appplication. Every time you click it, I am used to creating icons in the favorite column. Although most of the Linux systems deal with terminals, I still use UI when I still have UI, hee hee

Published 9 original articles · liked 0 · visits 860

Guess you like

Origin blog.csdn.net/weixin_43138930/article/details/105267703