search
Homephp教程PHP开发Configuring Java environment variables under Linux

Configuring Java environment variables under Linux

Dec 17, 2016 pm 01:35 PM
java environment variables

Generally speaking, we will install Java in the /usr/local directory or /opt directory. It is assumed here that the java installation package has been decompressed under /opt, and the specific directory is: /opt/java8/java1.8.0_45 directory (note: if it is a production environment, the root user must be installed and configured).

Let’s configure the java environment variables. Open /etc/profile and add:

export JAVA_HOME=/opt/jdk1.8.0_45
export JRE_HOME=$JAVA_HOME/jre                 #tomcat需要
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

Note: Be sure not to include spaces in the environment variables, otherwise an error will be reported.

After updating the profile, we execute the following statement (read and execute):

$ source  /etc/profile

Finally execute:

$ java -version

See whether the Java installation and configuration is successful! ! For the modified configuration file to finally take effect, you still need to log out and log in again or restart the computer! !

Because many Linux systems have openJDK installed by default, we have to do another job to set our newly installed Java as the default.

1. First check what java is available in the current environment

$ sudo update-alternatives --display java

Configuring Java environment variables under Linux

The current explicit default on my machine is openjdk7, and I switched to my own newly installed oracle java8.

2. Use update-alternatives to configure the newly installed oracle java8

$ sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_45/bin/java 1
$ sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_45/bin/javac 1
$ sudo update-alternatives --set java /opt/jdk1.8.0_45/bin/java
$ sudo update-alternatives --set javac /opt/jdk1.8.0_45/bin/javac

The above command is to configure the path of the new jdk and set it as the default! The update-alternatives --set command is equivalent to the update-alternatives --config command. If you do not use update-alternatives --set but use update-alternatives --config, like this:

Configuring Java environment variables under Linux



For more articles related to configuring Java environment variables under Linux, please pay attention to PHP Chinese website !

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor