Install JDK and configure environment variables on Ubuntu 16.04

System version: Ubuntu 16.04

JDK version: jdk1.8.0_121

  1. Download the JDK file jdk-8u121-linux-x64.tar.gz from the official website

I have the latest version here, other versions are also available

  1. Create a directory as the JDK installation directory, my directory is /java
sudo mkdir /java

  1. Move the file to the /java directory
sudo mv jdk-8u121-linux-x64.tar.gz /java

  1. unzip files
tar -zxvf jdk-8u121-linux-x64.tar.gz
  1. Configure environment variables
sudo gedit /etc/environment

Add the following configuration at the end (the path after JAVA_HOME is the file location of jdk)

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$JAVA_HOME/bin"export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export JAVA_HOME=/java/jdk1.8.0_121

Save and close after modification, and enter the following command to make the environment variable take effect immediately

source /etc/environment
  1. Enter java -version, the JDK version description is displayed. Congratulations, the environment variables are configured correctly

  1. But it's not over yet. According to articles written by other people, I found that it can't be used after every restart, so you need to configure environment variables for all users
sudo gedit /etc/profile

Add the following at the end of the file:

# set Java environment

export JAVA_HOME=/dengyang/jdk1.8.0_56
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
  1. Similarly, you need to use commands to make environment variables take effect immediately
source /etc/profile
  1. Restart the computer, you can enter the system normally, and the java -version command is valid

Reprinted from: http://www.linuxidc.com/Linux/2017-02/140908.htm

Recommended Posts

Install JDK and configure environment variables on Ubuntu 16.04
Install and configure MySQL on Ubuntu
Install and configure Mono production environment on Ubuntu Server
Install JDK10+ on Ubuntu
How to install and configure NATS on Ubuntu 16.04
How to install and configure Gogs on Ubuntu 18.04
How to install and configure Cyberpanel on Ubuntu 18.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure GitLab on Ubuntu 18.04
How to install and configure Ansible on Ubuntu 18.04
How to install and configure Elasticsearch on Ubuntu 16.04
How to install and configure PostGIS on Ubuntu 14.04
How to install and configure VNC on Ubuntu 18.04
How to install and configure Sphinx on Ubuntu 16.04
How to install and configure OrientDB on Ubuntu 14.04
How to install and configure AppScale on Ubuntu 12.04
How to install and configure PostGIS on Ubuntu 14.04
ubuntu install and configure GitLab
Ubuntu environment variables and ADB configuration
Install and configure Docker in Ubuntu
Docker ubuntu: install python-PIL-image environment on 14.04
Install Python virtual environment on Ubuntu 18.04
Configure python3 environment on centos7 and
Install Spark stand-alone environment on Spark Ubuntu18
Install Hadoop system environment on Ubuntu 18.04
How to install JDK and Mysql on Ubuntu 18.04 linux system
Install Gnome and VNC on Ubuntu Server
Install docker on ubuntu and basic usage
Install fonts on Ubuntu and switch default fonts
Install and uninstall CUDA and CUDNN on Ubuntu
install vscode on ubuntu18
How to install Pycharm and Ipython on Ubuntu 16.04/18.04
Install Redis on Ubuntu
Install R4 on ubuntu20
How to install and configure Elasticsearch on CentOS 7
Install nvtop on Ubuntu 18.04
Install postgresql-10 on Ubuntu 18.04
Install docker on Ubuntu
How to install and secure phpMyAdmin on Ubuntu 16.04
Install Docker on ubuntu18.04
Install and use Git and GitHub on Ubuntu Linux
Install nodejs10 on Ubuntu16
How to install and use Docker on Ubuntu 20.04
How to install and configure VNC on CentOS 8
Install mysql on Ubuntu 14.04
Install Django on ubuntu
How to install and use Curl on Ubuntu 18.04
How to install and use Composer on Ubuntu 18.04
Install Pytorch+CUDA on Ubuntu 16.04
How to install and use Wine on Ubuntu 18.04
Install Python3 on Ubuntu 14.04
How to install and secure phpMyAdmin on Ubuntu 16.04
How to install and configure Redis on CentOS 8
Install rJava on Ubuntu18
How to install and use Composer on Ubuntu 20.04
How to install and use BaasBox on Ubuntu 14.04
Install JDK in Ubuntu19.10
Install Python3 on Ubuntu 16.04
Ubuntu18.10 configure Java environment
How to install and use PostgreSQL on Ubuntu 16.04