【问题标题】:How to specify where CMake is installed in Ubuntu?如何指定 CMake 在 Ubuntu 中的安装位置?
【发布时间】:2018-11-12 08:54:03
【问题描述】:

我已经下载了cmake-3.11.3-Linux-x86_64.sh 文件。然后我执行了它,它创建了一个文件夹,里面有一个bin 文件,上面有cmake。我尝试像这样编辑/etc/environment

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/m/FILES/CMake/cmake-3.11.3-Linux-x86_64/bin"

但是当我尝试这个命令时:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

我收到这条消息:

当前未安装程序“cmake”。您可以通过以下方式安装它 输入:sudo apt install cmake

我所做的哪一部分是错误的,我该如何解决?

【问题讨论】:

    标签: ubuntu cmake installation


    【解决方案1】:

    我假设您从 CMake's Download Page 下载了脚本。诚然,如何使用它的文档有点稀疏。

    简而言之,调用(这里CMake的安装路径是/usr/local):

    # sudo cmake-3.11.3-Linux-x86_64.sh --skip-license --exclude-subdir --prefix=/usr/local
    

    注意:你需要先卸载任何包管理器安装的 CMake 包

    # sudo apt remove cmake
    # sudo apt purge --auto-remove cmake
    

    选项

    脚本有以下选项:

    # cmake-3.11.3-Linux-x86_64.sh --help
    Usage: cmake-3.11.3-Linux-x86_64.sh [options]
    Options: [defaults in brackets after descriptions]
      --help            print this message
      --version         print cmake installer version
      --prefix=dir      directory in which to install
      --include-subdir  include the cmake-3.11.3-Linux-x86_64 subdirectory
      --exclude-subdir  exclude the cmake-3.11.3-Linux-x86_64 subdirectory
      --skip-license    accept license
    

    您要搜索的是--prefix=dir。否则它只会使用当前目录来提取安装文件。

    在 Ubuntu 上测试输出

    # cmake-3.11.3-Linux-x86_64.sh --skip-license --exclude-subdir --prefix=/usr/local
    CMake Installer Version: 3.11.3, Copyright (c) Kitware
    This is a self-extracting archive.
    The archive will be extracted to: /usr/local
    
    Using target directory: /usr/local
    Extracting, please wait...
    
    Unpacking finished successfully
    
    # cmake --version
    cmake version 3.11.3
    
    CMake suite maintained and supported by Kitware (kitware.com/cmake).
    

    参考/替代

    【讨论】:

      【解决方案2】:

      而不是手动安装 CMake
      请让 apt 处理它。

      只需回滚您所做的任何更改。
      只需在终端上输入sudo apt install cmake

      您已经准备好使用 CMake,因为 apt 负责所有依赖项安装和环境变量设置。

      我希望,这会有所帮助。

      【讨论】:

      • 谢谢,但是它将安装什么版本的 CMake?
      • 这取决于存储库。最有可能的是最新的。如果你想检查,只需运行cmake --version
      • 你知道在我安装之前我可以搜索 Repo 以找到要安装哪个版本的命令吗!
      • $apt-cache madison cmake $apt-cache policy cmake 祝你好运!
      • 结果是 CMake 3.5.1 和 6 版本比我想安装的要早。但正如你建议的那样,我会安装它并希望它运行良好。
      猜你喜欢
      • 2015-07-23
      • 2014-02-19
      • 1970-01-01
      • 2014-07-26
      • 1970-01-01
      • 1970-01-01
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多