Configuring the Java environment Linux server, JDK

Foreword

  1. You can solve the problem have / etc / profile / .bashrc environmental differences between files with ~
  2. File permissions problem, read-only readonly
  3. Java environment to build

First, download the JDK package

  1. Address: jdk1.8 extraction code: gx0b
  2. The file into the directory on the server under Linux, but many go here, you can use Xftp, self-Baidu.
  3. Extract to / usr / lib / jvm , jvm If you do not create your own jvm folder, unzip command sudo tar -zxvf ./jdk-8u162-linux-x64.tar.gz -C / usr / lib / jvm

Second, select the files you need to configure the environment

  1. According to their own needs, if you want to only use Java environment at their current user, then select the configuration .bashrc file, if the system is to use server can then configure the / etc / profile file
  • If .bashrc configuration file that users can only use their own, relatively safe
首先使用自己的账户进入Linux,如果在root目录下,可以使用`su`命令切换到自己用户下
#cd ~
#vim ~/.bashrc
然后再文件中加入以下语句:
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_162
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
然后退出
然后执行生效语句,如果没有的话,就需要重启生效
#source ~/.bashrc
#java -version 
如果返回下面语句,就代表成功
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)
  • Configuration / etc / profile, similar to the above, another file on the line. If there is enough authority readonly, you can switch to the root user perform the modification.
#su root
#vim /etc/profile
加入语句
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_162
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
保存退出
#source /etc/profile
#java -version 

Guess you like

Origin www.cnblogs.com/tsruixi/p/12049270.html