ubunut 上搭建jdk 开发环境
2016-05-26 09:36
381 查看
jdk 切换:
sudo update-alternatives --config javasudo update-alternatives --config javac
转自:https://www.digitalocean.com/community/tutorials/how-to-install-java-on-ubuntu-with-apt-get
As a lot of articles and programs require to have Java installed, this article will guide you through the process of installing and managing different versions of Java.
This is the recommended and easiest option. This will install OpenJDK 6 on Ubuntu 12.04 and earlier and on 12.10+ it will install OpenJDK 7.
Installing Java with
Then, check if Java is not already installed:
If it returns "The program java can be found in the following packages", Java hasn't been installed yet, so execute the following command:
This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), which is usually needed to compile Java applications (for example Apache
Ant, Apache Maven, Eclipseand IntelliJ
IDEA execute the following command:
That is everything that is needed to install Java.
All other steps are optional and must only be executed when needed.
To install OpenJDK 7, execute the following command:
This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), execute the following command:
The Oracle JDK is the official JDK; however, it is no longer provided by Oracle as a default installation for Ubuntu.
You can still install it using apt-get. To install any version, first execute the following commands:
Then, depending on the version you want to install, execute one of the following commands:
This is an old version but still in use.
This is the latest stable version.
This is a developer preview, the general release is scheduled for March 2014. This external
article about Java 8 may help you to understand what it's all about.
When there are multiple Java installations on your Droplet, the Java version to use as default can be chosen. To do this, execute the following command:
It will usually return something like this if you have 2 installations (if you have more, it will of course return more):
You can now choose the number to use as default. This can also be done for the Java compiler (
It is the same selection screen as the previous command and should be used in the same way. This command can be executed for all other commands which have different installations. In Java, this includes but is not limited to:
To set the
It returns something like:
The path of the installation is for each:
Copy the path from your preferred installation and then edit the file
In this file, add the following line (replacing YOUR_PATH by the just copied path):
That should be enough to set the environment variable. Now reload this file:
Test it by executing:
If it returns the just set path, the environment variable has been set successfully. If it doesn't, please make sure you followed all steps correctly.
Submitted by: Koen Vlaswinkel
sudo update-alternatives --config javasudo update-alternatives --config javac
转自:https://www.digitalocean.com/community/tutorials/how-to-install-java-on-ubuntu-with-apt-get
Introduction
As a lot of articles and programs require to have Java installed, this article will guide you through the process of installing and managing different versions of Java.
Installing default JRE/JDK
This is the recommended and easiest option. This will install OpenJDK 6 on Ubuntu 12.04 and earlier and on 12.10+ it will install OpenJDK 7.Installing Java with
apt-getis easy. First, update the package index:
sudo apt-get update
Then, check if Java is not already installed:
java -version
If it returns "The program java can be found in the following packages", Java hasn't been installed yet, so execute the following command:
sudo apt-get install default-jre
This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), which is usually needed to compile Java applications (for example Apache
Ant, Apache Maven, Eclipseand IntelliJ
IDEA execute the following command:
sudo apt-get install default-jdk
That is everything that is needed to install Java.
All other steps are optional and must only be executed when needed.
Installing OpenJDK 7 (optional)
To install OpenJDK 7, execute the following command:sudo apt-get install openjdk-7-jre
This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), execute the following command:
sudo apt-get install openjdk-7-jdk
Installing Oracle JDK (optional)
The Oracle JDK is the official JDK; however, it is no longer provided by Oracle as a default installation for Ubuntu.You can still install it using apt-get. To install any version, first execute the following commands:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
Then, depending on the version you want to install, execute one of the following commands:
Oracle JDK 6
This is an old version but still in use.sudo apt-get install oracle-java6-installer
Oracle JDK 7
This is the latest stable version.sudo apt-get install oracle-java7-installer
Oracle JDK 8
This is a developer preview, the general release is scheduled for March 2014. This externalarticle about Java 8 may help you to understand what it's all about.
sudo apt-get install oracle-java8-installer
Managing Java (optional)
When there are multiple Java installations on your Droplet, the Java version to use as default can be chosen. To do this, execute the following command:sudo update-alternatives --config java
It will usually return something like this if you have 2 installations (if you have more, it will of course return more):
There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 auto mode 1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode 2 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 manual mode Press enter to keep the current choice[*], or type selection number:
You can now choose the number to use as default. This can also be done for the Java compiler (
javac):
sudo update-alternatives --config javac
It is the same selection screen as the previous command and should be used in the same way. This command can be executed for all other commands which have different installations. In Java, this includes but is not limited to:
keytool,
javadocand
jarsigner.
Setting the "JAVA_HOME" environment variable
To set the JAVA_HOMEenvironment variable, which is needed for some programs, first find out the path of your Java installation:
sudo update-alternatives --config java
It returns something like:
There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 auto mode 1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode 2 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 manual mode Press enter to keep the current choice[*], or type selection number:
The path of the installation is for each:
/usr/lib/jvm/java-7-oracle
/usr/lib/jvm/java-6-openjdk-amd64
/usr/lib/jvm/java-7-oracle
Copy the path from your preferred installation and then edit the file
/etc/environment:
sudo nano /etc/environment
In this file, add the following line (replacing YOUR_PATH by the just copied path):
JAVA_HOME="YOUR_PATH"
That should be enough to set the environment variable. Now reload this file:
source /etc/environment
Test it by executing:
echo $JAVA_HOME
If it returns the just set path, the environment variable has been set successfully. If it doesn't, please make sure you followed all steps correctly.
Submitted by: Koen Vlaswinkel
相关文章推荐
- Spring中的mvc:interceptors标签配置拦截器
- java 读取文件
- JAVACV人脸识别代码下载 酷~~
- java类静态方法测试
- eclipse3.7 安装github插件错误解决
- java maven诡异的错误no class found
- Java读取Properties文件中在配置
- java学习笔记继承和多态5.24
- eclipse,myeclipse导入工程报:javax.servlet.jsp.JspException cannot be resolved to a type
- Java并发编程
- (java)集合辅助函数之Shuffle(打乱列表)
- java多线程中终止线程的方法的对别
- Java关键字及其作用总览
- Java中判断对象是否相等的equals()方法使用教程
- Java用类和对象,构造方法来实现超市管理系统
- Java开发常用的在线工具
- java入门教程-7.6Java isAlive()和join()的使用
- java入门教程-7.5Java创建多线程
- java入门教程-7.4Java创建线程(Runnable接口和Thread类)
- java入门教程-7.3Java主线程