Ubuntu下配置MyEclipse环境

 jdk下载地址 http://download.Oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.tar.gz

我把jdk安装到/opt/java,所以在Terminal窗口里执行下面的代码:

sudo mkdir /opt/java

sudo tar zxvf jdk-7-linux-i586.tar.gz -C/opt/java

1. 用编辑器打开 /etc/environment

gedit /etc/environment

2. 修改文件

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:usr/games:${JAVA_HOME}/bin"

JAVA_HOME=/opt/java/jdk1.7.0

JRE_HOME=${JAVA_HOME}/jre

CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib"

3.打开bashrc文件

sudo gedit ~/.bashrc

4.添加如下代码

export JAVA_HOME=/opt/java/jdk1.7.0

export JRE_HOME=${JAVA_HOME}/jre

export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib

export PATH=${JAVA_HOME}/bin:$PATH

5. 重新加载bashrc

source ~/.bashrc

6.  配置默认JDK版本:由于Ubuntu中可能会有默认的JDK,如openjdk,所以,为了将我们安装的JDK设置为默认JDK版本,还要进行下面的配置:

sudo update-alternatives --install /usr/bin/java java /opt/java/jdk1.7.0/bin/java 300

sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk1.7.0/bin/javac 300

sudo update-alternatives --install /usr/bin/jar jar /opt/java/jdk1.7.0/bin/jar 300

sudo update-alternatives --install /usr/bin/javah javah /opt/java/jdk1.7.0/bin/javah 300

sudo update-alternatives --install /usr/bin/javap javap /opt/java/jdk1.7.0/bin/javap 300

7.然后执行:

sudo update-alternatives --config java

sudo update-alternatives --config javac

sudo update-alternatives --config jar

8.检测环境是否配好

java -version

java version "1.7.0"

Java(TM) SE Runtime Environment (build 1.7.0-b147)

Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode)

相关推荐