Ubuntu 系统下 Java 开发环境配置

[TOC]

1.JDK 安装

总的原则:将压缩包解压至/opt,设置jdk环境变量并将其修改为系统默认的jdk

1.将jdk-7u5-linux-x64.tar.gz拷贝到/usr/lib/jdk/目录下面,这里如果没有jdk文件夹,则创建该文件夹,命令:

sudo mkdir jdk //创建文件夹jdk

sudo cp -r ~/download/jdk-7u10-linux-x64.tar.gz /usr/lib/jdk/ //把下载的文件拷贝到新创建的目录下面

sudo tar -zxvg jdk-7u10-linux-x64.tar.gz //解压缩文件

2.设置环境变量,用gedit打开/etc/profile文件

sudo gedit /etc/profile

在文件的最后面增加:

export JAVA_HOME=/opt/jdk1.7.0_10

export JRE_HOME=/opt/jdk1.7.0_10/jre

export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

export CLASSPATH=$CLASSPATH:.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib

3.将系统默认的jdk修改过来

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

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

$ sudo update-alternatives --config java

$ sudo update-alternatives --config javac

4.检测,输入java -version

java version "1.7.0_10"

Java(TM) SE Runtime Environment (build 1.7.0_10-b18)

Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

2. Maven 安装

1) 从网站上下载linux版本的maven安装包;

2) 解压apache-maven-3.0.3-bin.tar.gz进行安装;

tar -xzvf apache-maven-3.0.3-bin.tar.gz

3) 设置maven环境变量;

vim /etc/profile或者vim /etc/environment

#jesse add maven envirment

export M2_HOME=/opt/apache-maven

export M2=$M2_HOME/bin

export MAVEN_OPTS="-Xms256m -Xmx512m"

export PATH=$M2:$PATH

4) 验证maven是否安装成功。

mvn -version

root@ciserver:/#mvn -version

Apache Maven 3.0.3(r1075438; 2011-02-28 17:31:09+0000)

Maven home:/opt/apache-maven

Java version:1.6.0_22, vendor: Sun Microsystems Inc.

Java home:/opt/jdk_1.7.0_15/jre

Default locale:zh_CN, platform encoding: GB2312

OS name:"linux", version: "2.6.38-8-server", arch: "amd64",family: "unix"

root@ciserver:/#echo $M2

/opt/apache-maven/bin

2013-02-27 14:50420mavenJDKUbuntu