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的变种,只不过安装到了其它路径。

猜你喜欢

转载自blog.csdn.net/dongzhensong/article/details/83053803