23

I am trying to upgrade cmake on my linux computer. Here is the command I used.

Remove the old cmake:

sudo apt purge --auto-remove cmake

Download and extracted cmake-3.13.3.tar.gz from https://cmake.org/download/

Then in the extracted cmake folder:

./bootstrap
make 
sudo make install 

when I did cmake --version it returns

bash: /usr/bin/cmake: No such file or directory

which indicates that no cmake executable exists in /usr/bin. However when I run which cmake it returns

/usr/local/bin/cmake

And that does exist.

How do I have the command cmake point to /usr/local/bin/cmake?

My $PATH shows

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Edit: different from the other question since I know exactly where the cmake executable is just that --version and which have different effect.

kkawabat
  • 1,530
  • 1
  • 14
  • 37
  • Difference between `which` output and actual running the executable by its name means that `cmake` in your case is an **alias**. See e.g. this question on Unix&Linux: https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then You need to remove that alias for make `cmake` to refer to its actual location. The question is not specific to `cmake`, and thus it is not about *programming*. – Tsyvarev Jan 29 '19 at 22:11
  • Possible duplicate of [How to check if a program exists from a Bash script?](https://stackoverflow.com/q/592620/608639) and [How to check if command exists in a shell script?](https://stackoverflow.com/q/7522712/608639) See the discussion of `which` versus `command -v`. Also relevant is [How to 'hash -r' and refresh all shells?](https://unix.stackexchange.com/q/398028/56041) and [When to rehash executables in $PATH with bash?](https://superuser.com/q/999439/173513) – jww Jan 30 '19 at 05:07

5 Answers5

48

In bash you can use hash -r so that it forgets all remembered locations of previously executed commands.

bbu
  • 663
  • 5
  • 6
19

It turns out I need to exit out of shell for the effect to take place. Once I start a new shell terminal cmake --version worked.

kkawabat
  • 1,530
  • 1
  • 14
  • 37
7

Making a symlink in /usr/bin worked for me:

sudo ln -s /usr/local/bin/cmake /usr/bin/cmake
synthetic64
  • 99
  • 1
  • 2
0

According to github/cmake readme:

 You may use the --prefix=<install_prefix> option to specify a custom installation directory for CMake. 

In boostrap script one can see, that the default cmake prefix installation is, from here:

cmake_default_prefix="/usr/local"

But I wouldn't just go with bootstrap --prefix=/usr. As I'm using archlinux, I would go with what the Archlinux uses for default installation, from here:

  ./bootstrap --prefix=/usr \
    --mandir=/share/man \
    --docdir=/share/doc/cmake \
    --sphinx-man \
    --system-libs \
    --qt-gui \
    --parallel=$(/usr/bin/getconf _NPROCESSORS_ONLN)

Looks reasonable. I see you use apt-get as your package manager, if that's debian, you can download source packages for cmake from here and find the build command somewhere there.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111
0

installation starts a new shell; when you type exit after the installation ends, cmake will work.

Cinar Eren
  • 91
  • 1
  • 8