Hasani
Hasani

Reputation: 3869

How to specify where CMake is installed in Ubuntu?

I have downloaded the cmake-3.11.3-Linux-x86_64.sh file. Then I executed it and it created a folder that has a bin file there is cmake on it. I tried to edit /etc/environment like this:

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"

But when I try this command:

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

I get this message:

The program 'cmake' is currently not installed. You can install it by typing: sudo apt install cmake

Which part of what I did, is wrong and how can I fix that?

Upvotes: 6

Views: 13386

Answers (3)

These are the following steps you need to do to upgrade your cmake to the latest version or download cmake if you don't have it:

Case 1: I have already have/downloaded cmake on my machine, but I want to upgrade it.

  1. If you already have/downloaded cmake before on your machine, then you need to remove it first:
sudo apt remove cmake
sudo apt purge --auto-remove cmake

Case 2: I never have cmake on my machine, but I want download it and I want the latest version.

  1. Just proceed to step 2.

  1. Download the binary distribution from cmake website, for example: cmake-3.25.1-linux-x86_64.sh
  2. Inside the directory where you have installed the binary distribution from step 2, run the command below (assume I have renamed the downloaded file to cmake.sh for simplicity):
sudo sh cmake.sh --prefix=/usr/local/ --exclude-subdir
  1. Check you have it installed by running:
cmake --version

The steps above won't require you to fix paths and all that, and they're simple steps you can do everytime you want to download the latest version of cmake.

Source:

Upvotes: 0

Florian
Florian

Reputation: 42852

I assume you downloaded the script from CMake's Download Page. The documentation how to use it is admittedly a little sparse.

In short, call (installation path for CMake here is /usr/local):

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

Note: You need to uninstall any package manager installed CMake packages first

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

Options

The script has the following options:

# 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

The one you are searching for is --prefix=dir. Otherwise it will just use the current directory to extract the installation files.

Test Output on 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).

Reference / Alternative

Upvotes: 7

Muhammad Iliyas
Muhammad Iliyas

Reputation: 172

Rather than installing CMake mannually,
Please let apt take care of it.

Just rollback whatever changes you've done.
Simply type sudo apt install cmake on your terminal.

and you're ready to use CMake since apt takes care of all dependencies installations and environment variable settings.

I hope, this will help.

Upvotes: 2

Related Questions