1. 程式人生 > >Mac cmake命令不可用-bash: cmake: command not found

Mac cmake命令不可用-bash: cmake: command not found

方法1與方法2親測可用
mac 版本 10.13.4(17E199)
最近因專案需要,安裝了cmake,但發現在命令列下不管用:

AppledeiMac:~ apple$ cmake --version
-bash: cmake: command not found
AppledeiMac:~ apple$ 

這是因為環境變數中缺少路徑,只需要在使用者根目錄的.bash_profile中新增上去即可

.bash_profile路徑:
.bash_profile檔案路徑

 # Add Cmake Root to Path
 export CMAKE_ROOT=/Applications/CMake.app/Contents/bin/
 export PATH=$CMAKE_ROOT:$PATH

新增完成後,開啟一個新的終端視窗,檢視cmake版本號:

AppledeiMac:~ apple$ cmake --version
cmake version 3.12.3

另外也可通過其它方式新增到命令列,開啟cmake圖形應用:
在這裡插入圖片描述

Tools–How to Install For Command Line Use:
在這裡插入圖片描述

One may add CMake to the PATH:

 PATH="/Applications/CMake.app/Contents/bin":"$PATH"

Or, to install symlinks to '/usr/local/bin', run:

 sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install

Or, to install symlinks to another directory, run:

 sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install=/path/to/bin

在這裡插入圖片描述

由圖上內容可知:上面使用的方法其實就是方法1,即 add CMake to the Path:…

方法1. 新增環境變數

見文章開頭。

方法2. 安裝symlinks

開啟終端執行:

 sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install

執行情況:

AppledeiMac:~ apple$  sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install
Password:
Linked: '/usr/local/bin/cmake' -> '/Applications/CMake.app/Contents/bin/cmake'
Linked: '/usr/local/bin/ctest' -> '/Applications/CMake.app/Contents/bin/ctest'
Linked: '/usr/local/bin/cpack' -> '/Applications/CMake.app/Contents/bin/cpack'
Linked: '/usr/local/bin/cmake-gui' -> '/Applications/CMake.app/Contents/bin/cmake-gui'
Linked: '/usr/local/bin/ccmake' -> '/Applications/CMake.app/Contents/bin/ccmake'
AppledeiMac:~ apple$ cmake --version
cmake version 3.12.3

方法3. 安裝symlinks到其它路徑

其實是方法2的變種,只不過安裝到了其它路徑。