Install jdk and configure environment variables under Linux operating system ubuntu17

  After working for many years, I have never really developed under Linux, and I have not fiddled with Linux servers. I recently learned Linux, used ubuntu17, installed jdk, and stepped on countless pits in the middle. This article is suitable for no Linux foundation, and it is a new computer that has not installed Linux system. This article has always used the root account. If it is an administrator account, add sudo before some commands.

  Based on the reality, let's start with a virtual machine:

Ready to work:

  1. I used VMware before, recently turned to VM VirtualBox and installed VirtualBox

  

  2. Install ubuntu17, I use ubuntukylin-17.10.1;

    Here I want to explain that during the installation process, you will be asked to enter a user name and password. This is the administrator account password, not the root account password. At that time, you need to upgrade and authorize. If you don’t understand, you will cry. After ubuntu is installed, there is no root password, it needs to be set, and the graphical interface cannot find a place to set root. After the installation is complete, there is no editor such as vim, which needs to be installed;

  3. If there is a desktop visual graphical interface, copy the jdk package to Linux, or directly download it with a browser in the virtual machine; if there is only a terminal interface, upload it with various tools and remember the path. Download the jdk file and choose 32-bit or 64-bit:

  

Got: jdk-8u171-linux-x64.tar.gz. If a worker wants to do a good job, he must first sharpen his tools. Now start the installation:

Installation work:

  1. User login: switch to the Linux terminal interface, some Linux has a directory that can be clicked, if not, press any one of Ctrl+Alt+F1 to F6 to enter the Linux terminal command line interface, press Ctrl+Alt+F7 Exit the command line interface.

  

  Enter the user name, password, the password is invisible when input, just enter it correctly, and then the login information will be displayed.

  2. Set the password of the system root user. If you need to use the root operation authority, you need to elevate the authority. Note that after Ubuntu is just installed, you cannot run the su command in the terminal, because root has no default password and needs to be set manually. Log in with the user name entered when installing ubuntu. This user is in the admin group and has permission to set a password for root.

  Under normal circumstances, we will not always use the root account to work. For security reasons, we generally use the administrator account.

  The specific steps to set a password for the root user:

  a. Open a terminal, and then enter the following command: sudo passwd root, follow the steps step by step, enter sudo passwd root and a flashing prompt will appear. Entering the root password will still not be displayed at this time, and then the sudo password will appear! That's it.

 

   

  b. Then users can switch between each other:

  

  3. Create a directory for storing jdk:

  

  Note: The file in Linux has permissions. It is no problem to create it under its own login folder, but we have no permission to create the custom directory that needs to be used under the root. You need:

  

  Appears mkdir:♦♦♦♦♦♦, this is unsuccessful, use sudo mkdir /usr/java1.80 and then it will flash to enter the root password, the password input is invisible, and the directory is created successfully after input.

  4. Copy the files to the new directory:

  

  Five, decompress jdk:

  Execute: $ tar -zxvf jdk-8u111-linux-x64.tar.gz to decompress it;

  Six: Configure environment variables, we use the vim editor to set, use the vim editor, there is no vim editor after the operating system is installed, as shown in the figure:

  

  Need to install vim editor: type: sudo apt-get install vim

  

  Enter Y, followed by a series of installation displays.

  After the installation is complete, enter vim ~/.bashrc; open the vim editor; press i to enter the editing state,

  enter:

  

  exit vim;

  Seven: Make the jdk environment variable take effect, enter: source ~/.bashrc

  Eight: Check the jdk version, enter Java -version:

  

 

 

Guess you like

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