下载
jdk
[root@Bhanv ~]# ll jdk/jdk-6u19-linux-i586-rpm.bin
-rwxr--r-- 1 root root 80366029 2010-04-09 jdk/jdk-6u19-linux-i586-rpm.bin
添家权限并安装
[root@Bhanv ~]# chmod o+x jdk/jdk-6u19-linux-i586-rpm.bin
[root@Bhanv ~]# ll jdk/jdk-6u19-linux-i586-rpm.bin
-rwxr--r-x 1 root root 80366029 2010-04-09 jdk/jdk-6u19-linux-i586-rpm.bin
[root@Bhanv ~]# ls jdk-6u19-linux-i586.rpm
jdk-6u19-linux-i586.rpm
[root@Bhanv ~]# rpm -ivh jdk-6u19-linux-i586.rpm
设置环境变量
[root@Bhanv ~]# export JAVA_HOME=/usr/java/jdk 1.6.0 _19/
[root@Bhanv~]#export CLASSPATH=/usr/java/jdk 1.6.0 _19/lib/dt.jar:/usr/java/jdk1.6.0_19/lib/tools.jar [root@Bhanvlib]# export CLASSPATH=.:/usr/java/jdk 1.6.0 _19/lib/dt.jar:/usr/java/jdk1.6.0_19/lib/tools.jar
[root@Bhanv lib]# export PATH=$PATH:/usr/java/jdk 1.6.0 _19/bin/
[root@Bhanv lib]# java -version
java version " 1.6.0 _19"
Java(TM) SE Runtime Environment (build 1.6.0 _19-b04)
Java HotSpot(TM) Client VM (build 16.2-b04, mixed mode, sharing)
创建测试
java
文件并编译测试:
[root@Bhanv ~]# cat test.java
class test
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
[root@Bhanv ~]# ll test.java
-rwxr-xr-x 1 root root 97 04-09 09:39 test.java
[root@Bhanv ~]# javac test.java
[root@Bhanv ~]# java test
Hello World!
刚才的设置只对当前登陆
shell
有效
,
用户注销就没有,可以写在用户的
.bashrc
中,如下
[root@Bhanv ~]#vi .bashrc
set JAVA_HOME=/usr/java/jdk 1.6.0 _02
export JAVA_HOME
set PATH=$PATH:$JAVA_HOME/bin
export PATH
set CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export CLASSPATH
要想让所有的用户都可以,将以上内容则写在
/etc/profile
,然后使用以下命令使其立即生效
[root@Bhanv ~]#source /etc/profile
←
使环境变量生效