首页 > 代码库 > Linux:Ubuntu 14.04 Server 离线安装Jjava8(及在线安装)
Linux:Ubuntu 14.04 Server 离线安装Jjava8(及在线安装)
- (离线安装)首先,通过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/hadoop
hadoop@master:~$ sudo cp -r jdk-8u102-linux-x64.gz /usr/lib
hadoop@master:~$ cd /usr/lib
hadoop@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$ ls
jdk1.8.0_102
hadoop@master:/usr/lib$ cd ..
hadoop@master:/usr/lib$ sudo rm jdk-8u102-linux-x64.gz
hadoop@master:/usr/lib$ cd jvm
hadoop@master:/usr/lib/jvm$ mv jdk1.8.0_102/ java-8-oracle
mv: cannot move ‘jdk1.8.0_102/’ to ‘java-8-oracle’: Permission denied
hadoop@master:/usr/lib/jvm$ sudo mv jdk1.8.0_102/ java-8-oracle/
hadoop@master:/usr/lib/jvm$ ls
java-8-oracle
hadoop@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-oracle
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export 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)
- (在线安装)安装java8
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保存并退出*/
参考:http://blog.csdn.net/sddi1989/article/details/7995042
Linux:Ubuntu 14.04 Server 离线安装Jjava8(及在线安装)