[TOC] # java安装 ## jdk8 * .在/usr/lib/目录下新建jvm文件夹,如果已有jvm文件夹,则将之前的JDK版本删除,即在jvm目录下执行命令:`rm –rf * ` * 将JDK文件jdk-8u40-linux-x64.gz拷贝到/home/目录下; * 在/home/目录下执行命令:`tar zxvf ./jdk-8u40-linux-x64.gz -C /usr/lib/jvm ` (注意:需要root权限) * .修改环境变量,执行命令:`vi /etc/profile ` * .在文件内容的末尾添加以下内容: ``` export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_40 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`查询java版本 ## openjdk ``` yum install java-1.8.0-openjdk ``` # 查看java安装路径 ## 查看 ``` [root@localhost ~]# whereis java java: /usr/bin/java /usr/lib/java /etc/java /usr/share/java /usr/share/man/man1/java.1.gz [root@localhost ~]# ls -lrt /usr/bin/java lrwxrwxrwx. 1 root root 22 Mar 7 03:00 /usr/bin/java -> /etc/alternatives/java [root@localhost ~]# ls -lrt /etc/alternatives/java lrwxrwxrwx. 1 root root 73 Mar 7 03:00 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre/bin/java ``` ## 编辑 `/etc/profile` ``` export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre/bin/java export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH ``` ## 环境变量生效 `source /etc/profile` ## 查看JAVA_HOME环境变量 ``` echo $JAVA_HOME ```