首页 > 解决方案 > 如何指定 CMake 在 Ubuntu 中的安装位置?

问题描述

我已经下载了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

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

标签: ubuntucmakeinstallation

解决方案


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

简而言之,调用(此处 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).

参考/替代


推荐阅读