install java 7 or 8 on Ubuntu

ubuntu 安装jdk 的两种方式:

1:通过ppa(源) 方式安装.

2:通过官网下载安装包安装.

这里推荐第1种,因为可以通过 apt-get upgrade 方式方便获得jdk的升级

使用ppa/源方式安装

1.添加ppa

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

2.安装oracle-java-installer

 jdk7

sudo apt-get install oracle-java7-installer

 jdk8

sudo apt-get install oracle-java8-installer

安装器会提示你同意 oracle 的服务条款,选择 ok

然后选择yes 即可

如果你懒,不想自己手动点击.也可以加入下面的这条命令,默认同意条款:

JDK7 默认选择条款

echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections

JDK8 默认选择条款

echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections

接下会是等待(依个人网速定)

如果你因为防火墙或者其他原因,导致installer 下载速度很慢,可以中断操作.然后下载好相应jdk的tar.gz 包,放在:

/var/cache/oracle-jdk7-installer             (jdk7)

/var/cache/oracle-jdk8-installer              (jdk8)

下面,然后安装一次installer. installer 则会默认使用 你下载的tar.gz包

3.设置系统默认jdk

JDk7

sudo update-java-alternatives -s java-7-oracle

JDK8

sudo update-java-alternatives -s java-8-oracle

如果即安装了jdk7,又安装了jdk8,要实现两者的切换,可以:

  jdk8 切换到jdk7

sudo update-java-alternatives -s java-7-oracle

  jdk7 切换到jdk8

sudo update-java-alternatives -s java-8-oracle

4.测试jdk 是是否安装成功:

java -version

javac -version

直接下载jdk压缩包方式安装(这里只介绍jdk7的,jdk8 的原理完全一致)

 分为下面5个步骤

1.官网下载JDK

2.解压缩,放到指定目录

3.配置环境变量

4.设置系统默认JDK

 5. 测试jdk

1.官网下载JDK   

     地址: http://www.oracle.com/technetwork/articles/javase/index-jsp-138363.html

  选择相应的 .gz包下载

2. 解压缩,放到指定目录(以jdk-7u60-linux-x64.gz为例)

  创建目录:

sudo mkdir /usr/lib/jvm

 加压缩到该目录:

 sudo tar -zxvf jdk-7u60-linux-x64.gz -C /usr/lib/jvm

3.修改环境变量:  

sudo vim ~/.bashrc

 文件的末尾追加下面内容:

#set oracle jdk environmentexport JAVA_HOME=/usr/lib/jvm/jdk1.7.0_60  ## 这里要注意目录要换成自己解压的jdk 目录
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH  

 使环境变量马上生效

 source ~/.bashrc

4.设置系统默认jdk 版本

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_60/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_60/bin/javac 300
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.7.0_60/bin/jar 300
sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk1.7.0_60/bin/javah 300
sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.7.0_60/bin/javap 300   

 然后执行:

sudo update-alternatives --config java

若是初次安装jdk,会有下面的提示

There is only one alternative in link group java (providing /usr/bin/java):
    /usr/lib/jvm/jdk1.7.0_60/bin/java

 否者,选择合适的jdk

5.测试jdk

java -version

java version "1.7.0_60"

  Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
  Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

jdk 安装成功

时间: 2024-10-12 00:38:28

install java 7 or 8 on Ubuntu的相关文章

Install Java in Ubuntu server

准备工作 a) 获得超级用户权限 关于超级用户访问权限的说明: 要将 Java 安装在系统级位置(例如 /usr/java),则必须以超级用户身份登录,从而获得必要的权限.如果您不具有超级用户访问权限,请将 Java 安装在您的主目录中,或者安装在您具有写入权限的子目录中 b) 从以下 java网站找到适合当前环境的安装包 http://www.java.com/en/download/manual.jsp 本文以安装版本 7 Update 67 for linux 64x为例 安装包链接:ht

How To Install Java with Apt-Get on Ubuntu 16.04

Koen Vlaswinkel Subscribe Share 29 How To Install Java with Apt-Get on Ubuntu 16.04 PostedApril 23, 2016 1.1mviews JAVA UBUNTU UBUNTU 16.04 Introduction Java and the JVM (Java's virtual machine) are widely used and required for many kinds of software

Install and Configure Apache Kafka on Ubuntu 16.04

https://devops.profitbricks.com/tutorials/install-and-configure-apache-kafka-on-ubuntu-1604-1/ by hitjethvaon Oct 03, 2016 Intermediate Table of Contents Introduction Features Requirements Getting Started Installing Java Install ZooKeeper Install and

【转】install intel wireless 3165 driver for ubuntu 14.04.3

[转]install intel wireless 3165 driver for ubuntu 14.04.3 Ubuntu 14.04.3 with 3.19 kernel can’t drive the new Intel Wireless 3165 AC with firmware version 13.This is about how to install the driver mannually. Today I changed a new Dell vastro 5000 ser

Install Redmine 3.2.0 on Ubuntu 14.04

To install redmine 3.2.0 on Ubuntu 14.04, mainly follow the tutorial: HowTo Install Redmine 3.0.x on Ubuntu 14.04 with Apache2, Phusion Passenger, MySQL, Subversion and Git (Gitolite) During the install process, some problems are encountered. The res

How to Install Java 7(JDK 7u60) On RHEL 6

Step1 Download Filehttp://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html#tar xzf jdk-7u60-linux-x64.gz Step2 Install JAVA using Alternatives#cd /home/oracle/alice/jdk1.7.0_60#[[email protected] jdk1.7.0_60]$ sudo -i[[ema

SDK Manager failed to install 'java.exe' locking directory

转自:http://stackoverflow.com/questions/13587478/sdk-manager-failed-to-install-java-exe-locking-directory I have ran into a curious error when trying to update Android SDK Tools to revision 21 from revision 20.0.3. The ADT plug-in updated properly so n

install the Mondo Rescue utility in Ubuntu 12.04 or 12.10.

  1. Open a terminal window. 2. Type in the following commands, then hit Enter after each. wget ftp://ftp.mondorescue.org/ubuntu/`lsb_release -r|awk '{print $2}'`/mondorescue.sources.listsudo sh -c "cat mondorescue.sources.list >> /etc/apt/sour

Install 32bit libraries in 64 bit ubuntu(14.10)

*/--> Install 32bit libraries in 64 bit ubuntu(14.10) I downloaded lingo11 (which is a cracked version,32bit), and when I was trying to run that program in 64 bit ubuntu, the bash complained that the target exection file did not exist. And I realized