Linux Debian 上安装 JDK7

本文详细介绍了在使用Debian Squeeze系统的服务器上安装Java 7的方法,包括添加额外的仓库、安装Java 7更新17、设置默认版本等步骤。

https://blog.retep.org/2013/04/13/installing-java-7-on-debian-squeeze/


INSTALLING JAVA 7 ON DEBIAN SQUEEZE

For all of my servers I use Debian, however that distribution has a few problems, mainly the packages can be a bit behind the cutting edge.

Now this is usually a good thing if you are looking for stability – cutting edge software can have issues, especially from new features etc, so for a live environment you want something thats stable.

However, there does come a time when this can bite back. You either need a feature thats not in the standard repositories or in this case the version is now unsupported.

In Debian Squeeze it has Java 6 – but that was EOL’d a couple of months ago so is no longer supported by Oracle. The current version is Java 7 update 17.

So how do we get Java 7 installed?

Well it’s pretty easy to do, we just need to add another repository into apt and install it.

First the repository:

1
2
3
4
5
6
sudo su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources .list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources .list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
apt-get update
exit

What that does is to install the ubuntu ppa repository into apt, setup the public keys and then load the package lists.

Next we need to install it:

1
sudo apt-get install oracle-java7-installer

This will now download Oracle Java 7 and present you with a couple of screens about licensing. Just ok and accept it and it will now install.

That’s it. You now have Java 7 installed – but it’s not the default JDK (if you already had Java 6 installed). If you want it to be the default then there’s just one more thing to do:

1
sudo apt-get install oracle-java7- set -default

That’s a dummy package but it will make Java 7 the default on that machine. If you want to check then you can check:

1
2
3
4
peter@titan ~ $ java -version
java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)


或者直接从oracle java官网下载安装

http://www.cnblogs.com/dogn/p/3308306.html

下载官方jdk:

当前版本是7u25

wget -c http://download.oracle.com/otn-pub/java/jdk/7u25-b15/jdk-7u25-linux-i586.tar.gz

(使用这个命令下载的文件不正确,会是一个网页。所以我是把jdk-7u25-linux-i586.tar.gz放到了自己的网站上下载的!)

将下jdk-7u25-linux-i586.tar.gz解压到/usr/lib/下

先解压在当前目录

tar vfxz jdk-7u25-linux-i586.tar.gz

重命名为jdk7并移动至/usr/lib/

mv jdk1.7.0_25/ /usr/lib/jdk7

修改环境变量

vi ~/.bashrc

内容如下:

export JAVA_HOME=/usr/lib/jdk7 
export JRE_HOME=${JAVA_HOME}/jre 
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib 
export PATH=${JAVA_HOME}/bin:$PATH

保存退出,输入以下命令使之立即生效。
source ~/.bashrc

 直接输入命令测试下

java


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值