让世间多点温暖 發表於 2022-8-4 14:01:00

正确的方式升级ubuntu的cmake

<div class="toc">
<h3>Ubuntu升级Cmake的正确方式</h3>
<br>某些软件包编译时需要高版本的Cmake,因此需要升级Cmake。&nbsp;不能使用&nbsp;<code>sudo apt-get remove cmake</code>卸载低版本cmake后再重装高版本,这样做会导致之前编译和安装的很多库一起被卸载!!!</div>
<p>&nbsp;</p>
<p>正确步骤是:</p>
<ol>
<li>
<p>去https://cmake.org/files/下载所需版本的源码。也可以使用wget下载,例如:</p>
<pre class="prettyprint" data-index="0"><code class="prism language-shell has-numbering"><span class="token function">wget https://cmake.org/files/v3.22/cmake-3.22.1.tar.gz</span></code></pre>
</li>
<li>
<p>解压:</p>
<pre class="prettyprint" data-index="1"><code class="has-numbering">tar -xvzf cmake-3.22.1.tar.gz</code></pre>
</li>
<li>
<p>进入解压目录,配置成功之后显示:<code>CMake has bootstrapped. Now run make.</code></p>
<pre class="prettyprint" data-index="2"><code class="has-numbering">chmod 777 ./configure
./configure   </code>如果遇到提示Could not find OpenSSL.&nbsp; Install an OpenSSL development package or ....... 需要安装 apt-get install libssl-dev</pre>
</li>
<li>
<p>配置完成后,编译:</p>
<pre class="prettyprint" data-index="3"><code class="has-numbering">make</code></pre>
</li>
<li>
<p>编译完成后,安装:</p>
<pre class="prettyprint" data-index="4"><code class="has-numbering">sudo make install</code></pre>
</li>
<li>
<p>最后使用新安装的cmake替换旧版本,其中<code>/usr/local/bin/cmake</code>为新安装的cmake目录。</p>
<pre class="prettyprint" data-index="5"><code class="has-numbering">sudo update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force</code></pre>
</li>
<li>
<p>最后测试cmake版本:</p>
<pre class="prettyprint" data-index="6"><code class="prism language-shell has-numbering">cmake --version
<span class="token comment"># cmake version 3.22.1

<span class="token comment"># CMake suite maintained and supported by Kitware (kitware.com/cmake).</span></span></code></pre>
</li>
</ol><br><br>
来源:https://www.cnblogs.com/Maker-Liu/p/16550381.html
頁: [1]
查看完整版本: 正确的方式升级ubuntu的cmake