一、搜索yum源中的CMake,查看源中最新的版本是什么,使用命令[root@localhost ~]# yum search cmake ,如果搜索出的结果过多可以配合grep命令来控制搜索结果。
[root@localhost ~]# yum search cmake Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: mirrors.yun-idc.com * extras: ftp.sjtu.edu.cn * updates: ftp.sjtu.edu.cn ============================================== N/S Matched: cmake ================================================
cmake-gui.i686 : Qt GUI for cmake cmake.i686 : Cross-platform make system Name and summary matches only, use "search all" for everything.
[root@localhost ~]#
二、查看yum源中的cmake版本
[root@localhost ~]# yum list cmake | grep cmake cmake.i686 2.8.12.2-4.el6 @base [root@localhost ~]#
三、查看yum源中的cmake安装包的cmake二进制文件(即:cmake命令)安装到系统中的真实目录,安装后可以通过which或whereis命令查看。
[root@localhost ~]# yum provides */cmake Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: mirrors.163.com * extras: mirrors.163.com * updates: mirrors.163.com 6:kdelibs-devel-4.3.4-28.el6.i686 : Header files for compiling KDE 4 applications Repo : base Matched from: Filename : /usr/share/kde4/apps/cmake ...... soprano-2.3.1-1.2.el6.i686 : Qt wrapper API to different RDF storage solutions Repo : base Matched from: Filename : /usr/share/soprano/cmake cmake-2.8.12.2-4.el6.i686 : Cross-platform make system Repo : base Matched from: Filename : /usr/share/cmake/completions/cmake Filename : /usr/share/cmake Filename : /usr/bin/cmake [root@localhost ~]#
从上面的记录可知yum源中的cmake包中的cmake命令会安装在/usr/bin目录,在yum安装jdk时javac和java等命令其实不是在/usr/bin 目录下。
执行命令 yum provides */javac 或 yum provides */java 结果如下:
[root@localhost ~]# yum provides */javac Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: mirrors.163.com * extras: mirrors.163.com * updates: mirrors.163.com 1:java-1.7.0-openjdk-javadoc-1.7.0.99-2.6.5.1.el6.noarch : OpenJDK API Documentation Repo : base Matched from: Filename : /usr/share/javadoc/java-1.7.0-openjdk/jdk/api/javac ...... 1:java-1.8.0-openjdk-devel-1.8.0.121-0.b13.el6_8.i686 : OpenJDK Development Environment Repo : installed Matched from: Filename : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.i386/bin/javac [root@localhost ~]#
发现其实是安装到/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.i386/bin 目录下
1:java-1.8.0-openjdk-devel-1.8.0.121-0.b13.el6_8.i686 : OpenJDK Development Environment
Repo : installed
Matched from:
Filename : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.i386/bin/javac
但是使用which和whereis命令查看发现是 /usr/bin目录,为啥?原因是通过alternatives映射,第五步中会有详细解释。
[root@localhost ~]# which javac
/usr/bin/javac
[root@localhost ~]# whereis javac
javac: /usr/bin/javac /usr/share/man/man1/javac.1.gz
[root@localhost ~]#
四、执行yum -y install cmake 命令安装 cmake-2.8.12.2-4
[root@localhost ~]# yum -y install cmake Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: mirrors.yun-idc.com * extras: ftp.sjtu.edu.cn * updates: ftp.sjtu.edu.cn Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package cmake.i686 0:2.8.12.2-4.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================================================== Package Arch Version Repository Size =================================================================================================================== Installing: cmake i686 2.8.12.2-4.el6 base 8.0 M Transaction Summary ===================================================================================================================
Install 1 Package(s) Total download size: 8.0 M Installed size: 28 M Downloading Packages: cmake-2.8.12.2-4.el6.i686.rpm | 8.0 MB 00:11 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : cmake-2.8.12.2-4.el6.i686 1/1 Verifying : cmake-2.8.12.2-4.el6.i686 1/1 Installed: cmake.i686 0:2.8.12.2-4.el6 Complete! [root@localhost ~]#
查看是否安装成功使用命令yum命令或rpm命令都是可以的如下:
使用yum 命令查看
[root@localhost ~]# yum list installed | grep cmake cmake.i686 2.8.12.2-4.el6 @base [root@localhost ~]#
已经安装成功了。
使用rpm命令查看
[root@localhost ~]# rpm -qa | grep cmake cmake-2.8.12.2-4.el6.i686 [root@localhost ~]#
也是可以的。
五、配置环境变量,通过上面的第三步的yum provides */cmak 命令可以看到cmke命令确实是安装在 /usr/bin 目录下所以不需要独配置环境变量直接执行cmake -version 查看cmake版本,源码安装的cmake是需要配置环境变量的。
[root@localhost ~]# cmake -version cmake version 2.8.12.2 [root@localhost ~]#
也不是所有采用yum安装的程序都会可执行二进制文件都会默认安装到 /usr/bin 下,例如yum安装jdk时可执行的二进制文件或命令都放在/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.i386/bin 下,执行java -version 也是可以的,为什么?因为在alternatives中注册,在/etc/alternatives目录下会产生一些链接到/usr/lib/jvm/中刚安装好的jdk版本。
===================================================================================================================
注:因为采用yum安装jdk,系统考虑到多版本的问题,会用alternatives进行版本控制。开始,相应版本的jdk安装在/usr/lib/jvm/之后,会在alternatives中注册,在/etc/alternatives目录下会产生一些链接到/usr/lib/jvm/中刚安装好的jdk版本。链接如下:
/usr/bin/java -> /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/jre-1.8.0-openjdk.i386/bin/java
为什么?
因为在/usr/bin下面会有链接到/etc/alternatives的相应的文件。通过
ls
-l 命令查看映射关系。
使用
ls
命令查看文件如果查看指定文件名并且不止一个文件时
ls
-l [file1 file2 file3 ...]
[root@localhost bin]# ls -l /usr/bin/java /usr/bin/javac lrwxrwxrwx. 1 root root 22 Feb 25 16:17 /usr/bin/java -> /etc/alternatives/java lrwxrwxrwx. 1 root root 23 Feb 25 16:17 /usr/bin/javac -> /etc/alternatives/javac [root@localhost bin]# ls -l /etc/alternatives/java /etc/alternatives/javac lrwxrwxrwx. 1 root root 44 Feb 25 16:17 /etc/alternatives/java -> /usr/lib/jvm/jre-1.8.0-openjdk.i386/bin/java lrwxrwxrwx. 1 root root 46 Feb 25 16:17 /etc/alternatives/javac -> /usr/lib/jvm/java-1.8.0-openjdk.i386/bin/javac [root@localhost bin]#
根据上面的信息追踪发现/usr/bin/java 下的java二进制命令是通过alternatives映射到了/usr/lib/jvm/jre-1.8.0-openjdk.i386/bin下的java二进制文件。
这样,java命令不用设置环境变量,就可以正常运行了。但如果对于tomcat或其他软件来说还是要设置环境变量。
同样,如果安装新的版本jdk,就会重新链接到最新安装的jdk版本。当然,也可以使用alternatives修改所要使用的版本。
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-02/141089.htm