How to Reinstall the Latest Cmake Version

How to reinstall the latest cmake version?

Following the comments made on how to Install the latest CMake version and to post the answer for this question:

Ans:

This depends with Ubuntu OS version currently installed on your PC or Mac. If you have the following Ubuntu OS version then you have this CMake installed or that you could install and reinstall with "sudo apt-get install cmake". Even if you uninstall your version and try to reinstall later version.

Ubuntu 16.04 ships with cmake-3.5.1
Ubuntu 17.10 ships with cmake-3.9.1
Ubuntu 18.04 ships with cmake-3.10.2
Ubuntu 20.04 ships with cmake-3.16.3
Ubuntu 21.04 ships with cmake-3.18.4

Now if you have Ubuntu 16.04 installed and you want cmake-3.10, there is OS problem since you can only install and reinstalled cmake-3.5.1. To get cmake-3.10 or any other version, you have to download and install the package from https://packages.ubuntu.com/. Once you find the latest version of cmake .targz files, you have to build it yourself from the command line.

Configure CMake version in Visual Studio 2019

You can download the latest CMake from here to your system. To point Visual Studio to this latest version, you have to edit your CMakeSettings.json file. You must change the value of the cmakeExecutable option to the installed location of the latest CMake version.

CMakeSettings.json:

  ...
"cmakeExecutable": "C:/path/to/new/cmake/executable",
...

How can I install CMake with PowerShell? (automatic installation)

ADD_CMAKE_TO_PATH=User does what it should do, but there are two problems in your case:

  1. You have to wait until msiexec.exe finishes. To do that, either pipe the result of the direct invocation to somewhere:

    msiexec.exe /i $exePath ADD_CMAKE_TO_PATH=User /qn | Out-Null

    Or use Start-Process with the -Wait parameter (which you already did):

    Start-Process msiexec.exe -ArgumentList "/i $exePath ADD_CMAKE_TO_PATH=User /qn" -Wait

    You can read more about that in this Q&A.

  2. When you update the environment variables of the Machine or User scope, existing processes will not inherit them into their existing Process scope. That's why your already running PowerShell process still does not know cmake after its installation. You can read more about that in this Q&A.

    You either have to start a really new PowerShell process (see above linked Q&A) or you have to reimport the environement variables of the Machine and User scope into your Process scope:

    foreach($level in "Machine","User") {
    [Environment]::GetEnvironmentVariables($level).GetEnumerator() | % {
    # For Path variables, append the new values, if they're not already in there
    if($_.Name -match 'Path$') {
    $_.Value = ($((Get-Content "Env:$($_.Name)") + ";$($_.Value)") -split ';' | Select -unique) -join ';'
    }
    $_
    } | Set-Content -Path { "Env:$($_.Name)" }
    }

    This code is taken from this answer.

    After that, cmake --version and Get-Command cmake will work.


Side notes:

  • If Start-Process can find msiexec.exe, then the direct invocation should also work. Maybe you just had a typo, when trying that.

  • A more PowerShelly way to download a file is:

    Invoke-WebRequest -Uri https://github.com/Kitware/CMake/releases/download/v3.24.0/cmake-3.24.0-windows-x86_64.msi -UseBasicParsing -OutFile $exePath


Related Topics



Leave a reply



Submit