1. 取得JDK,下载最新的JDK jdk-6-linux-i586.bin
2. 安装JDK(以root身份安装)
解压缩bin包
[root@localhost root]# mkdir /usr/java/
[root@localhost root]# cp jdk-6-linux-i586.bin /usr/java/
[root@localhost root]# cd /usr/java/
[root@localhost java]# ./jdk-6-linux-i586.bin
[root@localhost java]# rm -f jdk-6-linux-i586.bin
[root@localhost java]# gedit /root/.bash_profile &
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
BASH_ENV=$HOME/.bashrc
USERNAME="root"
JAVA_HOME=/usr/java/jdk1.6.0
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:/usr/java/jdk1.6.0/lib:$CLASSPATH
export USERNAME BASH_ENV PATH CLASSPATH JAVA_HOME
使配置生效
[root@localhost java]# source /root/.bash_profile
再查看一些环境变量是否已经成功设置好拉
[root@localhost java]# env
如果有如下类似信息就表明设置成功:
PATH=/usr/java/jdk1.6.0/bin:/usr/java/j2sdk1.4.2_01/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/root/bin:/root/bin
CLASSPATH=.:/usr/java/jdk1.6.0/lib:
[root@localhost java]# mkdir /home/workspace/helloworld
[root@localhost java]# cd /home/workspace/helloworld
写一个最简单的Java程序
[root@localhost helloworld]# vi hello.java
输入一下内容:
class hello
{
public static void main( String[] args )
{
System.out.println( "Hello world! My Java!" );
}
}
编译
[root@localhost helloworld]# javac hello.java
运行
[root@localhost helloworld]# java hello
Hello world! My Java!
在Linux系统中搭建Java开发环境
内容版权声明:除非注明,否则皆为本站原创文章。