首頁 > 軟體

使用yum安裝cmake

2020-06-16 17:21:04

一、搜尋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


IT145.com E-mail:sddin#qq.com