【初学Linux】Web开发环境搭建——JDK的安装

来源:互联网 发布:js课程设计 编辑:程序博客网 时间:2024/04/27 20:54

Linux版本 CentOS 7.0

关于Linux下jdk安装网上有好几种方法,这里选用的是通过Yum命令直接进行安装,省事省力,对于我这种懒人这就显得很关键了。


以下是操作步骤

1.查看yum库中都有哪些jdk版本(暂时只发现了openjdk)



2.选择jdk1.7.0进行安装,安装完成默认目录 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64

[root@localhost wyj]# yum install java-1.7.0-openjdk

依赖关系解决
============================================================================================================================================
 Package                                    架构                  版本                                         源                      大小
============================================================================================================================================
正在更新:
 java-1.7.0-openjdk                         x86_64                1:1.7.0.141-2.6.10.1.el7_3                   updates                231 k
为依赖而安装:
 copy-jdk-configs                           noarch                1.2-1.el7                                    base                    14 k
为依赖而更新:
 chkconfig                                  x86_64                1.7.2-1.el7_3.1                              updates                175 k
 java-1.7.0-openjdk-headless                x86_64                1:1.7.0.141-2.6.10.1.el7_3                   updates                 25 M
 nspr                                       x86_64                4.13.1-1.0.el7_3                             updates                126 k
 nss                                        x86_64                3.28.4-1.2.el7_3                             updates                872 k
 nss-softokn                                x86_64                3.16.2.3-14.4.el7                            base                   306 k
 nss-softokn-freebl                         x86_64                3.16.2.3-14.4.el7                            base                   204 k
 nss-sysinit                                x86_64                3.28.4-1.2.el7_3                             updates                 58 k
 nss-tools                                  x86_64                3.28.4-1.2.el7_3                             updates                496 k
 nss-util                                   x86_64                3.28.4-1.0.el7_3                             updates                 73 k
 ntsysv                                     x86_64                1.7.2-1.el7_3.1                              updates                 38 k


事务概要
============================================================================================================================================
安装           (  1 依赖软件包)
升级  1 软件包 (+10 依赖软件包)

3.安装完成需要进行环境变量的配置,终归还是需要自己配置,对于linux新手小白的我来说简直是灾难性的,vi命令什么的给跪了,为了方便以后使用,把命令贴出来。

(1)[root@localhost wyj]# vi /etc/profile

E325: ATTENTION
Found a swap file by the name "/etc/.profile.swp"
          owned by: root   dated: Thu Aug 17 10:26:48 2017
         file name: /etc/profile
          modified: YES
         user name: root   host name: localhost.localdomain
        process ID: 16008
While opening file "/etc/profile"
             dated: Thu Aug 17 10:33:55 2017
      NEWER than swap file!

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r /etc/profile"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/etc/.profile.swp"
    to avoid this message.
"/etc/profile" 83L, 2011C
Press ENTER or type command to continue

(2)按Entre进入文档编辑;

(3)操作光标跳到底行,按 “i”;

(4)粘贴命令

#set java environment
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH

(5)保存退出(按Esc进入命令界面,输入“:wq”保存并退出);

(6)重启生效[root@localhost wyj]# source /etc/profile



4. 安装完成查看java版本,验证是否安装成功。

[root@localhost wyj]# java -version
openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)

这就贼尴尬了,明明安装的是1.7.0咋就变成1.8.0了。


5.通过命令查看下linux下存在的jdk

root@localhost wyj]# rpm -qa | grep jdk
copy-jdk-configs-1.2-1.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.1.el7_3.x86_64

很明显,系统原来就有个1.8,自己又装了一个1.7,完美!考虑目前使用暂时没啥毛病,先这样了。



PS:中间安装JDK的时候遇到提示

Existing lock /var/run/yum.pid: another copy is running as pid 3404.
Another app is currently holding the yum lock; waiting for it to exit...

百度大神给出的建议直接干掉pid,然后重启,当时心里就七上八下,万一那啥咋办,但一想虚拟机怕个毛线,执行后顺利安装。

[root@centos5 ~]# rm -r /var/run/yum.pid
rm:是否删除 一般文件 “/var/run/yum.pid”? y
[root@centos5 ~]# /sbin/service yum-updatesd restart

阅读全文
1 0
原创粉丝点击