Mac/Linux环境下出现 cmake: command not found

文章目录

  • 1、 原因
  • 2、解决方法
    • 2.1 方法一:永久添加 环境变量
    • 2.2、方法二:暂时添加 环境变量
  • 3、查看是否解决

1、 原因

cmake: command not found`出现的原因有2个,一是未安装cmake, 二是因为环境变量中缺少路径。

本文主要针对环境变量中缺少路径情况。

2、解决方法

如何在环境变量中添加路径呢?只需要在用户根目录的.bash_profile中添加路径即可

2.1 方法一:永久添加 环境变量

# step1: open the .bash_profile 
$ cd 
$ touch .bash_profile
$ open .bash_profile  #for mac
#or
$ cd 
$ touch .bash_profile
$ vim .bash_profile  #for linux
# step2: Add Cmake Root to Path ,at the end of .bash_profile 
 export CMAKE_ROOT=/Applications/CMake.app/Contents/bin/
 export PATH=$CMAKE_ROOT:$PATH
 
#step3: update the .bash_profile
$ source .bash_profile

2.2、方法二:暂时添加 环境变量

此方法在bash窗口被关闭后即失效,再次使用需要重复执行。

# for temporary use
 export PATH="/Applications/CMake.app/Contents/bin":"$PATH"

3、查看是否解决

添加完成后,打开一个新的终端窗口,查看cmake版本号:

$ cmake --version
cmake version 3.15.2

你可能感兴趣的:(Mac/Linux环境下出现 cmake: command not found)