linux安装jdk

来源:互联网 发布:网络影视广告视频教程 编辑:程序博客网 时间:2024/06/10 09:14

在linux上安装jdk已经做过很多次了,这是抽时间简单记一下。

首先要下载好jdk安装包,版本要和系统对应。

然后记得切换用户进行操作,稍微麻烦点的就是配置环境变量了。


我直接把操作的一些过程贴出来:


上传jdk安装包,记得不要用root用户,jdk安装到哪里随便,自己建个目录即可。上传后要改安装包的执行权限,中间会切换root用户,但是改完要记得再切回你的用户。[lsy@localhost ~]$ pwd/home/lsy[lsy@localhost ~]$ [lsy@localhost ~]$ [lsy@localhost ~]$ lsDesktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos[lsy@localhost ~]$ [lsy@localhost ~]$ [lsy@localhost ~]$ [lsy@localhost ~]$ mkdir jdk[lsy@localhost ~]$ [lsy@localhost ~]$ [lsy@localhost ~]$ lsDesktop  Documents  Downloads  jdk  Music  Pictures  Public  Templates  Videos[lsy@localhost ~]$ [lsy@localhost ~]$ [lsy@localhost ~]$ [lsy@localhost ~]$ [lsy@localhost ~]$ ls Documentsjdk-6u45-linux-x64.bin[lsy@localhost ~]$ [lsy@localhost ~]$ [lsy@localhost Documents]$ su - rootPassword: [root@localhost ~]# [root@localhost Documents]# ls -ltotal 70400-rw-rw-r--. 1 lsy lsy 72087592 Mar  2 18:43 jdk-6u45-linux-x64.bin[root@localhost Documents]# [root@localhost Documents]# chmod 775 jdk-6u45-linux-x64.bin[root@localhost Documents]# [root@localhost Documents]# [root@localhost Documents]# ls -ltotal 70400-rwxrwxr-x. 1 lsy lsy 72087592 Mar  2 18:43 jdk-6u45-linux-x64.bin[root@localhost Documents]# [root@localhost Documents]# [root@localhost Documents]# su - lsy[lsy@localhost ~]$ [lsy@localhost ~]$ [lsy@localhost ~]$ [lsy@localhost ~]$ [lsy@localhost ~]$ [lsy@localhost ~]$ [lsy@localhost ~]$ lsDesktop  Documents  Downloads  jdk  Music  Pictures  Public  Templates  Videos[lsy@localhost ~]$ cd Documents[lsy@localhost Documents]$ ls -ltotal 70400-rwxrwxr-x. 1 lsy lsy 72087592 Mar  2 18:43 jdk-6u45-linux-x64.bin[lsy@localhost Documents]$ [lsy@localhost Documents]$ [lsy@localhost Documents]$ [lsy@localhost Documents]$ java -verrsion-bash: java: command not found[lsy@localhost Documents]$ [lsy@localhost Documents]$ [lsy@localhost Documents]$ [lsy@localhost Documents]$ mv jdk-6u45-linux-x64.bin /home/lsy/jdk[lsy@localhost Documents]$ [lsy@localhost Documents]$ [lsy@localhost Documents]$ ls[lsy@localhost Documents]$ [lsy@localhost Documents]$ cd /home/lsy/jdk[lsy@localhost jdk]$ lsjdk-6u45-linux-x64.bin[lsy@localhost jdk]$ ls -ltotal 70400-rwxrwxr-x. 1 lsy lsy 72087592 Mar  2 18:43 jdk-6u45-linux-x64.bin[lsy@localhost jdk]$ [lsy@localhost jdk]$ ./jdk-6u45-linux-x64.bin中间打印好多,截取最后几行: extracting: jdk1.6.0_45/LICENSE       inflating: jdk1.6.0_45/THIRDPARTYLICENSEREADME.txt    inflating: jdk1.6.0_45/src.zip       inflating: jdk1.6.0_45/README.html     creating: jdk1.6.0_45/include/  inflating: jdk1.6.0_45/include/jni.h     creating: jdk1.6.0_45/include/linux/  inflating: jdk1.6.0_45/include/linux/jawt_md.h    inflating: jdk1.6.0_45/include/linux/jni_md.h    inflating: jdk1.6.0_45/include/jvmti.h    inflating: jdk1.6.0_45/include/jawt.h    inflating: jdk1.6.0_45/include/jdwpTransport.h    inflating: jdk1.6.0_45/include/classfile_constants.h    inflating: jdk1.6.0_45/COPYRIGHT   Creating jdk1.6.0_45/jre/lib/rt.jarCreating jdk1.6.0_45/jre/lib/jsse.jarCreating jdk1.6.0_45/jre/lib/charsets.jarCreating jdk1.6.0_45/lib/tools.jarCreating jdk1.6.0_45/jre/lib/ext/localedata.jarCreating jdk1.6.0_45/jre/lib/plugin.jarCreating jdk1.6.0_45/jre/lib/javaws.jarCreating jdk1.6.0_45/jre/lib/deploy.jar Done.[lsy@localhost jdk]$ [lsy@localhost jdk]$ [lsy@localhost jdk]$ pwd/home/lsy/jdk[lsy@localhost jdk]$ [lsy@localhost jdk]$ [lsy@localhost jdk]$ [lsy@localhost jdk]$ lsjdk1.6.0_45  jdk-6u45-linux-x64.bin[lsy@localhost jdk]$ [lsy@localhost jdk]$ [lsy@localhost jdk]$ [lsy@localhost jdk]$ 出现了jdk1.6.0_45[lsy@localhost jdk]$ [lsy@localhost jdk]$ cd jdk1.6.0_45[lsy@localhost jdk1.6.0_45]$ lsbin  COPYRIGHT  db  include  jre  lib  LICENSE  man  README.html  src.zip  THIRDPARTYLICENSEREADME.txt[lsy@localhost jdk1.6.0_45]$ [lsy@localhost jdk1.6.0_45]$ pwd/home/lsy/jdk/jdk1.6.0_45[lsy@localhost jdk1.6.0_45]$ [lsy@localhost jdk1.6.0_45]$ java -version-bash: java: command not found[lsy@localhost jdk1.6.0_45]$ 需要配置环境变量。安装成功后就要配置环境变量,简答说就是要修改/etc/profile文件,改完后source一下。这个profile属于root,所以要用root修改权限,一般考虑安全,我们都是修改成775,即root组中的用户可以编辑和执行,所以你的用户不在root组,还要把用户加进root组中。[lsy@localhost etc]$ pwd/etc[lsy@localhost etc]$ [lsy@localhost etc]$ vi profile这里先不编辑,先退出,环境变量的编辑,我们最好指定具体内容,不用累加的方式,因为,你如果第一次没配置成功,在第2次的时候就有累积了一次。(累计就是用冒号:)所以先用export查看环境变量,再把jdk环境变量加入。[lsy@localhost etc]$ [lsy@localhost etc]$ exportdeclare -x G_BROKEN_FILENAMES="1"declare -x HISTCONTROL="ignoredups"declare -x HISTSIZE="1000"declare -x HOME="/home/lsy"declare -x HOSTNAME="localhost.localdomain"declare -x LANG="en_US.UTF-8"declare -x LESSOPEN="|/usr/bin/lesspipe.sh %s"declare -x LOGNAME="lsy"declare -x LS_COLORS="rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:"declare -x MAIL="/var/spool/mail/lsy"declare -x OLDPWD="/home/lsy/jdk/jdk1.6.0_45"declare -x PATH="/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/lsy/bin"declare -x PWD="/etc"declare -x SHELL="/bin/bash"declare -x SHLVL="1"declare -x SSH_ASKPASS="/usr/libexec/openssh/gnome-ssh-askpass"declare -x TERM="vt100"declare -x USER="lsy"[lsy@localhost etc]$ 我们要添加export JAVA_HOME=/home/lsy/jdk/jdk1.6.0_45export JAVA_BIN=$JAVA_HOME/binexport PATH=$PATH:$JAVA_HOME/binexport CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jarexport JAVA_HOME JAVA_BIN PATH CLASSPATH注意path和classpath就是累加的方式,如果多次执行就会出现重复。所以这里我们就把具体的值写到上面去。改成如下:export JAVA_HOME=/home/lsy/jdk/jdk1.6.0_45export JAVA_BIN=$JAVA_HOME/binexport PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/lsy/bin:$JAVA_HOME/binexport CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jarexport JAVA_HOME JAVA_BIN PATH CLASSPATH修改profile需要root权限,原始内容如下[lsy@localhost etc]$ [lsy@localhost etc]$ [lsy@localhost etc]$ ls -l profile-rw-r--r--. 1 root root 1793 Mar 23  2012 profile[lsy@localhost etc]$ [lsy@localhost etc]$ [lsy@localhost etc]$ [lsy@localhost etc]$ cat profile# /etc/profile# System wide environment and startup programs, for login setup# Functions and aliases go in /etc/bashrc# It's NOT a good idea to change this file unless you know what you# are doing. It's much better to create a custom.sh shell script in# /etc/profile.d/ to make custom changes to your environment, as this# will prevent the need for merging in future updates.pathmunge () {    case ":${PATH}:" in        *:"$1":*)            ;;        *)            if [ "$2" = "after" ] ; then                PATH=$PATH:$1            else                PATH=$1:$PATH            fi    esac}if [ -x /usr/bin/id ]; then    if [ -z "$EUID" ]; then        # ksh workaround        EUID=`id -u`        UID=`id -ru`    fi    USER="`id -un`"    LOGNAME=$USER    MAIL="/var/spool/mail/$USER"fi# Path manipulationif [ "$EUID" = "0" ]; then    pathmunge /sbin    pathmunge /usr/sbin    pathmunge /usr/local/sbinelse    pathmunge /usr/local/sbin after    pathmunge /usr/sbin after    pathmunge /sbin afterfiHOSTNAME=`/bin/hostname 2>/dev/null`HISTSIZE=1000if [ "$HISTCONTROL" = "ignorespace" ] ; then    export HISTCONTROL=ignorebothelse    export HISTCONTROL=ignoredupsfiexport PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL# By default, we want umask to get set. This sets it for login shell# Current threshold for system reserved uid/gids is 200# You could check uidgid reservation validity in# /usr/share/doc/setup-*/uidgid fileif [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then    umask 002else    umask 022fifor i in /etc/profile.d/*.sh ; do    if [ -r "$i" ]; then        if [ "${-#*i}" != "$-" ]; then            . "$i"        else            . "$i" >/dev/null 2>&1        fi    fidoneunset iunset pathmunge[lsy@localhost etc]$ [lsy@localhost etc]$ [root@localhost etc]# pwd/etc[root@localhost etc]# [root@localhost etc]# [root@localhost etc]# ls -l profile-rw-r--r--. 1 root root 1793 Mar 23  2012 profile[root@localhost etc]# [root@localhost etc]# [root@localhost etc]# chmod 775 profile[root@localhost etc]# ls -l profile-rwxrwxr-x. 1 root root 1793 Mar 23  2012 profile[root@localhost etc]# [root@localhost etc]# l profile-rwxrwxr-x. 1 root root 1793 Mar 23  2012 profile[lsy@localhost etc]$ [lsy@localhost etc]$ [lsy@localhost etc]$ 为了保证安全,root对对文件的权限最多到775,就是该组的用户可以修改和执行,我们用的用户如果不在root用户的组中,那么就把这个用户添加到root所在的组中,查看文件可以发现root的组也是叫root。用命令吧lsy添加进组root。usermod -G root lsy  加入root组[root@localhost ~]# [root@localhost ~]# usermod -G root lsy[root@localhost ~]# [root@localhost ~]# 文摘:将一个用户添加到用户组中,千万不能直接用:usermod -G groupA这样做会使你离开其他用户组,仅仅做为 这个用户组 groupA 的成员。应该用 加上 -a 选项:usermod -a -G groupA user(FC4: usermod -G groupA,groupB,groupC user)-a 代表 append, 也就是 将自己添加到 用户组groupA 中,而不必离开 其他用户组。[lsy@localhost etc]$ [lsy@localhost etc]$ [lsy@localhost etc]$ source /etc/profile[lsy@localhost etc]$ [lsy@localhost etc]$ [lsy@localhost etc]$ [lsy@localhost etc]$ java -versionjava version "1.6.0_45"Java(TM) SE Runtime Environment (build 1.6.0_45-b06)Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)[lsy@localhost etc]$ [lsy@localhost etc]$ 这时jdk就安装成功了。把profile贴出来[lsy@localhost etc]$ [lsy@localhost etc]$ cat /etc/profile# /etc/profile# System wide environment and startup programs, for login setup# Functions and aliases go in /etc/bashrc# It's NOT a good idea to change this file unless you know what you# are doing. It's much better to create a custom.sh shell script in# /etc/profile.d/ to make custom changes to your environment, as this# will prevent the need for merging in future updates.pathmunge () {    case ":${PATH}:" in        *:"$1":*)            ;;        *)            if [ "$2" = "after" ] ; then                PATH=$PATH:$1            else                PATH=$1:$PATH            fi    esac}if [ -x /usr/bin/id ]; then    if [ -z "$EUID" ]; then        # ksh workaround        EUID=`id -u`        UID=`id -ru`    fi    USER="`id -un`"    LOGNAME=$USER    MAIL="/var/spool/mail/$USER"fi# Path manipulationif [ "$EUID" = "0" ]; then    pathmunge /sbin    pathmunge /usr/sbin    pathmunge /usr/local/sbinelse    pathmunge /usr/local/sbin after    pathmunge /usr/sbin after    pathmunge /sbin afterfiHOSTNAME=`/bin/hostname 2>/dev/null`HISTSIZE=1000if [ "$HISTCONTROL" = "ignorespace" ] ; then    export HISTCONTROL=ignorebothelse    export HISTCONTROL=ignoredupsfiexport PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROLexport JAVA_HOME=/home/lsy/jdk/jdk1.6.0_45export JAVA_BIN=$JAVA_HOME/binexport PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/lsy/bin:$JAVA_HOME/binexport CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jarexport JAVA_HOME JAVA_BIN PATH CLASSPATH# By default, we want umask to get set. This sets it for login shell# Current threshold for system reserved uid/gids is 200# You could check uidgid reservation validity in# /usr/share/doc/setup-*/uidgid fileif [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then    umask 002else    umask 022fifor i in /etc/profile.d/*.sh ; do    if [ -r "$i" ]; then        if [ "${-#*i}" != "$-" ]; then            . "$i"        else            . "$i" >/dev/null 2>&1        fi    fidoneunset iunset pathmunge[lsy@localhost etc]$ [lsy@localhost etc]$ [lsy@localhost etc]$ [lsy@localhost etc]$ 把环境变量贴出来[lsy@localhost etc]$ [lsy@localhost etc]$ [lsy@localhost etc]$ exportdeclare -x CLASSPATH=".:/home/lsy/jdk/jdk1.6.0_45/lib/dt.jar:/home/lsy/jdk/jdk1.6.0_45/lib/tools.jar:/home/lsy/jdk/jdk1.6.0_45/jre/lib/rt.jar"declare -x G_BROKEN_FILENAMES="1"declare -x HISTCONTROL="ignoredups"declare -x HISTSIZE="1000"declare -x HOME="/home/lsy"declare -x HOSTNAME="localhost.localdomain"declare -x JAVA_BIN="/home/lsy/jdk/jdk1.6.0_45/bin"declare -x JAVA_HOME="/home/lsy/jdk/jdk1.6.0_45"declare -x LANG="en_US.UTF-8"declare -x LESSOPEN="|/usr/bin/lesspipe.sh %s"declare -x LOGNAME="lsy"declare -x LS_COLORS="rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:"declare -x MAIL="/var/spool/mail/lsy"declare -x OLDPWD="/home/lsy"declare -x PATH="/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/lsy/bin:/home/lsy/jdk/jdk1.6.0_45/bin"declare -x PWD="/etc"declare -x SHELL="/bin/bash"declare -x SHLVL="1"declare -x SSH_ASKPASS="/usr/libexec/openssh/gnome-ssh-askpass"declare -x TERM="vt100"declare -x USER="lsy"[lsy@localhost etc]$ [lsy@localhost etc]$ [lsy@localhost etc]$ 








0 0
原创粉丝点击