**What is JDK? **
Well, if you don’t know this question, I really don’t know why you want to install this thing.
JDK (Java Development Kit) is an object-oriented programming language development kit launched by Sun (later acquired by Oracle). After having this kit, we can use the Java language for program design and development.
Today, we need to deploy this thing in the Linux environment so that it can be developed, and it is installed in a compressed package and decompressed way. The reason why the installation is not in rpm is mainly to be universal on all Linux systems, rpm and deb It can only be installed separately on Red Hat and Debian's Linux systems at most, and there will be mutual conversion problems, but using compressed packages will not have this problem, although it is relatively cumbersome.
Operating system: CentOS Linux Release 8.0.1905 (Core)
Environment: Virtual Box virtual machine
Then I just want Java programs to run on me? ?
If you are too lazy to find or can’t find the JRE installation tutorial, then you have the right and you can also follow this process to ensure that your Java program can actually run, but your Linux operating system will have a lot more. You actually Something not needed at all.
What if I want to install another version? ?
Versions of JDK 8 and below may be different from this, please refer to other special installation procedures for installing JDK 8.
There should not be much difference in the process above JDK 10, but please be sure to note that some locations need to be replaced with your current version code when referring.
Why should you install it on Linux? ? Don't you prefer to use Eclipse for Java development on the Windows platform? ?
There are so many questions about you. You are right, but under special needs, I have to take some "I don't like" behavior.
And this is one, because I need to deploy Hadoop under the Linux platform, and there is no Java environment in the newly installed CentOS:
[ user@localhost /]$ java -version
bash: java: command not found...
And Java SE is a prerequisite for Hadoop
And if it is deployed, I can also use Linux for Java development. Isn’t it beautiful? ?
But it seems that there are many similar tutorials on the Internet
When did I say that this is a tutorial? ? This is just a record of my process. If possible, I hope it can be a reference for others. I also refer to the installation process of many people. In the end, I succeeded.
Standing on the shoulders of countless giants.
Well, not much to say, let's get started.
Well, it does. First, you need to install a Linux system. It doesn’t need to be CentOS. It can also be Ubuntu, Fedora, Debian, whatever you like. It doesn’t matter whether you use a GUI or not, because even if I install a CentOS with a GUI, my installation process is actually The above is done with bash commands.
Before the actual installation, I must explain in advance:
Unlike Windows, Linux systems are case sensitive, which means that /Somewhere/a.zip and /somewhere/A.zip are not in the same directory, nor are they the same file name. Please pay attention to this! ! !
The real content of all shell commands that appear below starts after the $.
As for whether you are a physical machine or a virtual machine, there should not be a big difference. You can actually take a USB flash drive to install it, or you can use VMWare or Virtual Box. I will not explain here.
Download JDK compressed package
In short, I have installed CentOS 8. Of course, you may use Ubuntu 16.04 or whatever. Then you have to download a JDK13 compressed package (jdk-13_linux-x64_bin.tar.gz) from the Internet.
It is assumed here that you have downloaded the compressed package to the /usr/download directory regardless of whether it is GUI download or wget download.
If your Linux system has a GUI and the system is pre-installed with Firefox, then you can use Firefox to rush to the JDK download address like in Windows, like this:
If there is no GUI, you can use the wget command:
[ user@localhost /usr/lib/jvm/jdk-13]$ su root #
The whole process needs to be elevated to root privileges, because ordinary users cannot modify the usr, etc folders and their subfolders
[ root@localhost /]$ mkdir /usr/download #If you don’t have this directory, type this command first, otherwise go to the next sentence
[ root@localhost /]$ cd /usr/download
[ root@localhost /usr/download]$ wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/13+33/5b8a42f3905b406298b72d750b6919f6/jdk-13_linux-x64_bin.tar.gz
Note: Because the Oracle official website requires you to log in to the Oracle account to download JDK and other content, so type directly
wget https://download.oracle.com/otn-pub/java/jdk/13+33/5b8a42f3905b406298b72d750b6919f6/jdk-13_linux-x64_bin.tar.gz
The downloaded jdk-13_linux-x64_bin.tar.gz
is only 5KB (in fact, it should be 180MB), that thing is not a compressed package at all but a request page. So if you download through the command line, you can only download through the above method
After downloading, check the properties of jdk-13_linux-x64_bin.tar.gz:
[ root@localhost /]$ ls -al jdk-13_linux-x64_bin.tar.gz
- rw-rw-r--.1 user user 1887114479May 1911:13 jdk-13_linux-x64_bin.tar.gz
In some Linux operating systems, the location of the file name is displayed in red at this time, which means:
This is a compressed file
So don't worry, this is not an error, you can proceed.
If you find that 188711447 (about 180MB) has been replaced by 5307 (about 5KB) (that is, the file size is severely inconsistent), it means that your download link is wrong. Please read the content in the "Note" above and use rm jdk -13_linux-x64_bin.tar.gz delete this file and download it again. If the size is inconsistent but it is about the same size, you may have downloaded another version, or the compressed package may be damaged. If it is the latter, please download it again.
Unzip the files in the JDK installation package
Next, use the tar command to unzip the compressed package and unzip it to the /usr/lib/jvm directory:
[ root@localhost /usr/download]$ mkdir /usr/lib/jvm
[ root@localhost /usr/download]$ tar -xf jdk-13_linux-x64_bin.tar.gz -C /usr/lib/jvm #--Please wait patiently for this step, it will take a while
[ root@localhost /usr/download]$ cd /usr/lib/jvm
[ root@localhost /usr/lib/jvm]$ ls
jdk-13
You will see there is a folder called jdk-13 under /usr/lib/jvm, let's go in and take a look
[ root@localhost /usr/lib/jvm]$ cd jdk-13[root@localhost /usr/lib/jvm/jdk-13]$ ls
bin conf include jmods legal lib man release
At this point, all the components of the JDK have been prepared, and the next step is to configure.
Add environment variables
Note: VIM is required here
If you know how to use vim
Ah, that's okay, go ahead
If you don't know how to use vim
If you are using a Linux system with a GUI interface
You can use the pre-installed text editor to edit, just like using Notepad in Windows.
otherwise
If you want to learn about vim
Find other people's tutorials to see the basic operation method of VIM
Otherwise, if you have a trustworthy and capable friend
Ask him to help you
otherwise
emmm...I am heartily sad for you
Generally speaking, environment variables are automatically configured when using the installer under Windows, but unfortunately we are installing manually now. The work of the JDK depends on the path in a large number of environment variables.
It seems that the software of the Oracle department is all the dead son, such as Oracle DB...
The JDK requires several environment variables:
JAVA_HOME: The home directory of Java, the location of the jdk-13 folder you get after decompressing the compressed package (and including jdk-13 itself)
JRE_HOME: The home directory of JRE. JRE is the most basic software environment for running Java applications, so if you just want Java programs to run, you don't need to install JDK at all, even though JDK contains JRE.
CLASSPATH: the location of standard or public class libraries provided by Java
PATH: This is the system environment variable. This thing only tells the system where your Java development environment is installed. This thing allows you to directly execute Java development tools such as javac in any directory. Just type javac directly. It can be executed without having to retype /usr/lib/jvm/jdk-13/bin/javac.
The environment variables under Linux system are stored in several files, and their scope of action is different. Some only affect the current user, and some affect all users. And our environment here is directly effective for all users (because I am a user except root), so here we will modify /etc/profile.
But we now know that JAVA_HOME=/usr/lib/jvm/jdk-13, this directory means that it contains all things related to the Java runtime environment, let’s see what’s inside
[ user@localhost /usr/lib/jvm/jdk-13]$ ls
bin conf include jmods legal lib man release
Among them, bin is the directory where all Java development tools (usually executable applications) are located, and the lib is the public class library provided by Java. Of course, this is the CLASSPATH we are looking for.
So, what about JRE_HOME? ?
As early as JDK 8, a folder called jre could be found under the installed JAVA_HOME, but when I arrived at JDK 13, I also looked at it. Where is jre? ?
In fact, there is no need to consider this issue, because the new version of JDK not only comes with JRE, but also destroys the JRE components directly into the JDK, so JRE_HOME can be directly given as JAVA_HOME.
So we use VIM to open /etc/profile (because it is) for editing:
[ root@localhost /usr/lib/jvm/jdk-13]$ vim /etc/profile
Add the following at the beginning of this file:
export JAVA_HOME=/usr/lib/jvm/jdk-13export JRE_HOME=/${JAVA_HOME}export CLASSPATH=.:${JAVA_HOME}/libss:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
Then: wq save and exit, but because these environment variables are only written in the file, these environment variables are not actually built into the kernel, so you need to manually execute this file.
[ root@localhost /usr/lib/jvm/jdk-13]$ source /etc/profile
[ root@localhost /usr/lib/jvm/jdk-13]$ exit #Exit root privileges
At this point, the installation process is all over and the JDK can work normally, we can use the following command to check:
[ user@localhost /usr/lib/jvm/jdk-13]$ java -version
Now we can use JDK13 for development on Linux systems.
Now that it's installed, let's try it!
Yes! ! We are already gearing up, so write a Java program to test it!
Just create a folder in a certain location and write a Hello World to try:
[ user@localhost /usr/lib/jvm/jdk-13]$ mkdir ~/jsrc
[ user@localhost /usr/lib/jvm/jdk-13]$ cd ~/jsrc
[ user@localhost ~/jsrc]$ vim Hello.java
/// Hello.javapublicclassHello{publicstaticvoidmain(String args[]){
System.out.println("Hello");}}[user@localhost ~/jsrc]$ javac Hello.java
[ user@localhost ~/jsrc]$ ls
Hello.classHello.java[user@localhost ~/jsrc]$ java Hello
Hello
to sum up
The above is the method of installing JDK 13 in the Linux environment by compressed package method introduced by the editor, I hope it will be helpful to you!
Recommended Posts