Alibaba Cloud Linux server installation JDK operating environment tutorial

Today I will talk to you about the most basic jdk operating environment deployment and installation, and then I will share with you some more complex project environment deployment, such as oracle database installation, redis non-relational database installation, and project deployment, etc., no gossip Say, let’s see how to do it next!

Practice is the only criterion for testing truth

Step 1: Assuming that the production environment gave you a server to install jdk at this time, you should first check whether the server has jdk installed, whether you can use the existing jdk, or if you cannot use the existing jdk, uninstall it first The jdk that the server already has

#Check if the server has installed jdk

Command: java -version

If there is jdk related version information, for example:

OpenJDK Runtime Environment (IcedTea6 1.7.4) (rhel-1.21.b17.el6-i386)
OpenJDK Client VM (build 14.0-b16, mixed mode)

#View the jdk package information installed by the server

Command: rpm -qa|grep gcj

If there is jdk package information, for example:

libgcj-4.4.4-13.el6.i686
java-1.5.0-gcj-1.5.0.0-29.1.el6.i686

#Uninstall package

命令:yum -y remove java-1.5.0-gcj-1.5.0.0-29.1.el6.i686

You need to check the specific output according to the actual output. Some linux servers come with OpenJDK or have installed jdk. You must learn to judge whether you can use it. For example, whether the version is the version you want, or the oracle jdk, Or use Linux's own OpenJDK. If you are not sure, you must communicate with the relevant personnel on the customer site to determine the jdk version used in the server production environment.

Step 2: Download jdk, first download jdk on oracle

Command: wget http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz

The host attaches the JDK8 version that he downloaded. This article is the Linux x64 version.

JDK8 (Linux+x64) download address: jdk8 download address

Many people on the Internet will tell you to do this. Let me tell you, this is a bit of nonsense. I don’t know what the Nima is under. Little Alan has tried this way himself. The gz downloaded this way The package cannot be decompressed by gzip at all, indicating that the downloaded package is problematic. If you are interested, you can decompress it without using gzip. After decompression, you can see what the download is. Little Alan will not go into it. ,Let's continue reading

gzip:tar -xzvf jdk-8u111-linux-x64.tar.gz -C usr/java  

no gzip:tar -xvf jdk-8u111-linux-x64.tar.gz -C usr/java  

So, we first need to get the jdk installation package, where is the jdk installation package? You can search it online, but it’s better to download one from the oracle website, which is safer and more secure

Official website address: http://www.oracle.com/technetwork/java/javase/downloads/index.html , the address may be changed, it is more flexible, Baidu "jdk download" and other keywords can generally be seen oracle's official website.

Here little Alan chose jdk8, 9 is too new after all, and little Alan has not touched it, as shown in the figure:

Click the DOWNLOAD button under jdk to go to the download interface, remember to agree to the agreement, here in order to hit the arrow Alan, download the following version:

Choose the Linux x64 tar.gz package, click to download it locally, we usually use the windows system, just throw it in one place, as long as you can find it.

Step 3: Upload the downloaded jdk installation package to the linux server. First of all, you must make sure that you can ping the linux server locally, and the linux server must enable the ssh service, so that you can connect to the linux server and upload files through the tool. If the ping fails To access the Linux server, you must find a solution by yourself or communicate with the relevant personnel on the customer site, ask them to provide support, and then install a file upload tool locally, here we use WinSCP, this tool is relatively simple and easy to use, convenient for demonstration, of course some The customer environment has their own special operation and maintenance environment. You have to use the tools they provide. Some companies with higher security levels can only access the real server through the bastion machine.

In addition, there are two more mainstream remote connection tools xshell+xftp.

[Linux server remote connection tool]

xshell6 quick download , xftp6 quick download  Most people use these two.
Reminder: xshell is responsible for writing and executing Linux commands, which is the command line that everyone knows.
xftp is responsible for uploading and downloading files. Use the two software together. There is also a free domestic Linux remote connection client—finalshell, a software that integrates the functions of xshell and xftp at the same time. The finalshell download address is now using this software.

Open WinSCP, fill in the connection information, upload our jdk installation package through the sftp protocol, and click save to save

Click Login, you can access the files in Linux

Just drag and drop the jdk installation package to the corresponding location of the linux server. Here I store it in the /usr/lib/java directory file and create a directory: mkdir /usr/lib/java.

Step 4: Unzip the jdk installation package, and install and configure the environment variables

#Create installation directory (variable according to actual situation)

Command: mkdir /usr/java

Here we use the putty tool to access the linux server, it is very simple and easy to use like WinSCP

You can log in by entering the linux user name and password. The same requires the linux server to enable the ssh service and switch to the jdk installation package storage path

We can see that the jdk installation package is here, which is the one we dragged in, let us unzip it

Little Alan has already decompressed it and will not decompress it. Decompression will get such a file: jdk1.8.0xxx. At this time, for convenience, you can change the name to java8.

Command: mv jdk1.8.0xxx java8

Switch to the user's home directory, you can use the cd ~ command to find the .bashrc file

Can’t find what is the case, because it is a hidden file, we can display all files through ls -a, including hidden files

Next, open this file and edit it through vi.bashrc command editing. After opening, press i to enter the editing mode. Add the environment variable configuration content at the end of the file and press exit to exit the editing mode and return to the command mode. Enter: wq to save and exit vim

Refresh the .bashrc file

Note: The environment variable that we configure now belongs to the current user. If you want to configure the global one, use the following method. Of course, there are other methods, which will not be explained here. Things are dead but people are alive.

The last step: Let's test whether the jdk operating environment is installed successfully. It can be tested through the java -version command or directly input the java command

In this way, the jdk operating environment is successfully installed on the Linux server.

Concluding remarks: A small grass can also spring spring, a drop of water can also moisturize, a trace of wind can also send coolness, a star of fire can also start a prairie fire. Although I am small and valuable, I believe in myself, I am born to be useful!

Guess you like

Origin blog.csdn.net/wx_15323880413/article/details/108264809