广告

本站里的文章大部分经过自行整理与测试

2016年5月2日星期一

Linux - Java Development Kit (jdk) 安装

Ubuntu - Java 6 / 7 / 8 / 9 (jdk) 安装
http://jasonmun.blogspot.my/2016/04/ubuntu-java-6-7-8-9.html


下载 jdk-8u91-linux-x64.tar.gz
http://www.oracle.com/technetwork/java/javase/downloads/index.html

以下列出在 Ubuntu / Linux Mint / Centos / Fedora 安装 Java 的仔细过程

Ubuntu
# 怕麻烦, 建议还是用 add-apt-repository 的方法安装 Java
$ sudo mkdir /usr/lib/jvm
$ sudo tar -zxvf
jdk-8u91-linux-x64.tar.gz -C /usr/lib/jvm

$ sudo vim ~/.bashrc
 

export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_91 
export CLASSPATH="$JAVA_HOME/lib/dt.jar:
$JAVA_HOME/lib/tools.jar" 
export PATH=$JAVA_HOME/bin:$PATH 

$ source ~/.bashrc


$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/
jdk1.8.0_91/bin/java 300
$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/
jdk1.8.0_91/bin/javac 300
$ sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/
jdk1.8.0_91/bin/jar 300
$ sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/
jdk1.8.0_91/bin/javah 300
$ sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/
jdk1.8.0_91/bin/javap 300
$ sudo update-alternatives --config java


Linux Mint
# 卸载与清理 OpenJdk
$ sudo apt-get update && apt-get remove openjdk*
$ sudo apt-get autoremove && apt-get clean

# 已下载 jdk-8u91-linux-x64.tar.gz 放到 ~/Downloads
$ cd ~/Downloads
$ tar -zxvf jdk-*
$ sudo mkdir -p /opt/java/64
$ sudo mv jdk1.8.0_* /opt/java/64

$ sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/64/jdk1.8.0_91/bin/java" 1
$ sudo update-alternatives --set java /opt/java/64/jdk1.8.0_91/bin/java

# 将 firefox 连接到 Java
$ mkdir -p ~/.mozzila/plugins

$ ln -s /opt/java/64/jdk1.8.0_91/jre/lib/amd64/libnpjp2.so ~/.mozzila/plugins/
$ ln -s /opt/java/32/jdk1.8.0_91/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/


$ sudo gedit /etc/profile

export JAVA_HOME=/opt/java/64/jdk1.8.0_91
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

$ source /etc/profile


Centos
# 已下载 jdk-8u91-linux-x64.tar.gz 放到 ~/Downloads
$ cd ~/Downloads
$ su


# 32-bit Java
$ rpm -Uvh jdk-8u91-linux-i586.rpm
# 64-bit Java
$ rpm -Uvh jdk-8u91-linux-x64.rpm

# java
$ alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_91/jre/bin/java 200000
# javaws
$ alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.8.0_91/jre/bin/javaws 200000

# Java Browser (Mozilla) Plugin 32-bit
$ alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/jdk1.8.0_91/jre/lib/i386/libnpjp2.so 200000
# Java Browser (Mozilla) Plugin 64-bit
$ alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/jdk1.8.0_91/jre/lib/amd64/libnpjp2.so 200000


# Install javac only if you installed JDK (Java Development Kit) package
$ alternatives --install /usr/bin/javac javac /usr/java/jdk1.8.0_91/bin/javac 200000
$ alternatives --install /usr/bin/jar jar /usr/java/jdk1.8.0_91/bin/jar 200000

$ alternatives --config java
$ alternatives --config javaws

# 32-bit Java Plugin
$ alternatives --config libjavaplugin.so

# 64-bit Java Plugin
$ alternatives --config libjavaplugin.so.x86_64
$ alternatives --config javac

$ vi /etc/profile

export JAVA_HOME=/usr/java/jdk1.8.0_91
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar


$ source /etc/profile

Fedora
$ su

$ update-alternatives --config java

# 已下载 jdk-8u91-linux-x64.tar.gz 放到 ~/Downloads
$ cd ~/Downloads
$ tar -zxvf jdk-*
$ mkdir /usr/java
$ mv jdk1.8.0_* /usr/java




# 已下载 jdk-8u91-linux-x64.rpm 放到 ~/Downloads
$ cd ~/Downloads
$ dnf install jdk-8u91-linux-x64.rpm # Fedora 22 开始
$ yum install jdk-8u91-linux-x64.rpm # Fedora 21 或以下
$ vi /etc/profile

export JAVA_HOME=/usr/java/jdk1.8.0_91
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

没有评论:

发表评论