- (离线安装)首先,通过winscp上传本地下载好的jdk-8u102-linux-x64.gz
- (离线安装)将jdk-8u102-linux-x64.gz解压到到/usr/lib/jvm下,并把文件夹名重命名为java-8-oracle:
hadoop@master:/usr/lib$ mkdir jvm
hadoop@master:/usr/lib$ ls。。。jvm 。。。
hadoop@master:/usr/lib$ cd /home/hadoophadoop@master:~$ sudo cp -r jdk-8u102-linux-x64.gz /usr/libhadoop@master:~$ cd /usr/libhadoop@master:/usr/lib$ ls
... jdk-8u102-linux-x64.gz ...
hadoop@master:/usr/lib$ sudo tar -zxvf jdk-8u102-linux-x64.gz -C jvm/
hadoop@master:/usr/lib$ cd jvm
hadoop@master:/usr/lib/jvm$ lsjdk1.8.0_102hadoop@master:/usr/lib$ cd ..
hadoop@master:/usr/lib$ sudo rm jdk-8u102-linux-x64.gzhadoop@master:/usr/lib$ cd jvmhadoop@master:/usr/lib/jvm$ mv jdk1.8.0_102/ java-8-oraclemv: cannot move ‘jdk1.8.0_102/’ to ‘java-8-oracle’: Permission deniedhadoop@master:/usr/lib/jvm$ sudo mv jdk1.8.0_102/ java-8-oracle/hadoop@master:/usr/lib/jvm$ lsjava-8-oraclehadoop@master:/usr/lib/jvm$- (离线安装)设置环境变量
hadoop@master:~$ sudo vim /etc/profile 在profile文件末尾追加一下行:
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export JRE_HOME=/usr/lib/jvm/java-8-oracleexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATHexport CLASSPATH=$CLASS_PATH::$JAVA_HOME/lib:$JAVA_HOME/jre/lib(esc,:wq!保存)hadoop@master:~$ sudo update-alternatives --install /usr/bin/Java java /usr/lib/jvm/java-8-oracle/bin/java 300update-alternatives: using /usr/lib/jvm/java-8-oracle/bin/java to provide /usr/bin/Java (java) in auto modehadoop@master:~$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-8-oracle/bin/javac 300update-alternatives: using /usr/lib/jvm/java-8-oracle/bin/javac to provide /usr/bin/javac (javac) in auto modehadoop@master:~$ sudo update-alternatives --config javaThere is only one alternative in link group java (providing /usr/bin/Java): /usr/lib/jvm/java-8-oracle/bin/javaNothing to configure.hadoop@master:~$ sudo update-alternatives --config javacThere is only one alternative in link group javac (providing /usr/bin/javac): /usr/lib/jvm/java-8-oracle/bin/javacNothing to configure.
- (离线安装)测试是否安装好
java -version我测试不行,于是重启了服务器,发现可以。
hadoop@master:~$ java -versionjava version "1.8.0_102"Java(TM) SE Runtime Environment (build 1.8.0_102-b14)Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
- 在线安装方法一:
sudo add-apt-repository ppa:webupd8team/javasudo apt-get updatesudo apt-get install Oracle-java8-Installer
如果在执行 sudo add-apt-repository ppa:webupd8team/java 命令时,提示“Cannot add PPA:xxx”,一般是因为CA证书损坏。执行如下命令修复:
sudo apt-get install --reinstall ca-certificates
设置JAVA_HOME环境变量:
$ vim /etc/profile
在文件最前面添加如下单独一行(注意 = 号前后不能有空格),并保存:
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
/*按esc 输入 :wq保存并退出*/
-
在线安装方法二:
wget http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz?AuthParam=1522506006_6fffc05b7c064c1b0023fd4a4f8612b8mv jdk-8u161-linux-x64.tar.gz\?AuthParam\=1522506006_6fffc05b7c064c1b0023fd4a4f8612b8 jdk-8u161-linux-x64.tar.gzmkdir /usr/local/java/ tar -zxvf jdk-8u161-linux-x64.tar.gz -C /usr/local/java/vi /etc/profile在/etc/profile 末尾添加以下记录:# config java class pathexport JAVA_HOME=/usr/local/java/jdk1.8.0_161export JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/libexport PATH=${JAVA_HOME}/bin:$PATHsource /etc/profile测试java -version[root@localhost jdk1.8.0_161]# java -versionjava version "1.8.0_161"Java(TM) SE Runtime Environment (build 1.8.0_161-b12)Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)[root@localhost jdk1.8.0_161]# vi /etc/profile
针对方法二,也可以参考:https://blog.csdn.net/fuyuwei2015/article/details/73195936
参考: