下载JDK(jdk1.7.0_45)
下载地址为:http://pan.baidu.com/share/link?shareid=1744393420&uk=336215391&fid=2600365656
1.解压安装文件:tar -xzvf jdk-7u45-linux-x64.tar.gz,解压后得到 jdk1.7.0_45 文件夹;
2.将其移动到/usr/local/(安装目录可以自由选择)目录下,命令为:sudo mv jdk1.7.0_45 /usr/local/
上面JDK已经安装完成,下面来配置环境变量:
1.进入root用户下,把下面的代码加入/etc/profile最后面:
export JAVA_HOME=/usr/jdk1.7.0_45
export JRE_HOME=/usr/jdk1.7.0_45/jre
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
在/etc目录下执行:source profile
在任意目录下面执行java或javac,输出如下信息则说明配置成功:
[root@cloud001 ~]# java
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
The default VM is server,
because you are running on a server-class machine.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property。。。。。。
[root@cloud001 ~]# javac
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files and annotation processors
-cp <path> Specify where to find user class files and annotation processors
-sourcepath <path> Specify where to find input source files。。。。。。
这样的设置将对所以用户的shell都生效,对系统安全会产生影响,所以最好的方法还是修改.bashrc文件。
2.修改.bashrc文件配置环境变量:
.bashrc文件是隐藏文件,在用户根目录下;
比如你用户名是user,那么你的家(home)目录就在/home/user
在控制台下输入:
cd ~
ls -a (列举当前目录下所有文件)
就可以看到.bashrc文件了。
编辑可以用vi或者你喜欢的编辑器:
#vi .bashrc
set JAVA_HOME=/usr/jdk1.7.0_45
export JAVA_HOME
set JRE_HOME=/usr/jdk1.7.0_45/jre
export JRE_HOME
set PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export PATH
setCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar::$JRE_HOME/lib
export CLASSPATH