心静自然爽 發表於 2019-11-17 17:21:00

ubuntu安装rust开发环境

<div>一、rust的安装</div>
<div>因为国内防火墙的原因,导致rust不能正常安装,如此有2个选择:</div>
<div>1、搭墙,因为FQ有风险而且速度也不佳,此处不推荐并省略。</div>
<div>2、使用中科大的代理</div>
<div>Rust Toolchain 反向代理:https://mirrors.ustc.edu.cn/help/rust-static.html</div>
<div>Rust Crates 源使用帮助:https://mirrors.ustc.edu.cn/help/crates.io-index.html</div>
<div>Rust 官网:https://www.rust-lang.org/learn/get-started</div>
<div>以下在Ubuntu上安装过一遍,linux的其他发行版应该也没有问题,除了.bashrc可能是profile</div>
<div>&nbsp;</div>
<div>直接复制下面的shell代码执行即可,安装过程会提示选择,选择默认项即可,也可以自定义选择安装。</div>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> <span style="color: rgba(0, 0, 0, 1)"># import USTC mirror
</span><span style="color: rgba(0, 128, 128, 1)">2</span> <span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/<span style="color: rgba(0, 0, 0, 1)">.bashrc
</span><span style="color: rgba(0, 128, 128, 1)">3</span> <span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/<span style="color: rgba(0, 0, 0, 1)">.bashrc
</span><span style="color: rgba(0, 128, 128, 1)">4</span> <span style="color: rgba(0, 0, 0, 1)">source .bashrc
</span><span style="color: rgba(0, 128, 128, 1)">5</span>
<span style="color: rgba(0, 128, 128, 1)">6</span> curl --proto <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">=https</span><span style="color: rgba(128, 0, 0, 1)">'</span> --tlsv1.<span style="color: rgba(128, 0, 128, 1)">2</span> -sSf https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">sh.rustup.rs | sh</span>
<span style="color: rgba(0, 128, 128, 1)">7</span>
<span style="color: rgba(0, 128, 128, 1)">8</span> <span style="color: rgba(0, 0, 0, 1)"># 安装完毕后刷新环境变量
</span><span style="color: rgba(0, 128, 128, 1)">9</span> source ~/.cargo/<span style="color: rgba(0, 0, 255, 1)">env</span></pre>
</div>
<p>&nbsp;</p>
</div>
<div>
<p>安装rust后,可以执行&nbsp;<span class="cnblogs_code">rustc -V </span>&nbsp;和&nbsp;<span class="cnblogs_code">cargo -V</span>&nbsp;,看看是否正常输出版本。如果输出正常,那恭喜你,成功了一半了。接下来配置插件和cargo</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)"> 1</span> <span style="color: rgba(0, 0, 0, 1)"># cargo代理
</span><span style="color: rgba(0, 128, 128, 1)"> 2</span> <span style="color: rgba(0, 0, 255, 1)">cat</span> &gt;~/.cargo/config &lt;&lt;<span style="color: rgba(0, 0, 0, 1)">EOF
</span><span style="color: rgba(0, 128, 128, 1)"> 3</span>
</span><span style="color: rgba(0, 128, 128, 1)"> 4</span> replace-with = <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">ustc</span><span style="color: rgba(128, 0, 0, 1)">'</span>
<span style="color: rgba(0, 128, 128, 1)"> 5</span>
<span style="color: rgba(0, 128, 128, 1)"> 6</span> <span style="color: rgba(0, 0, 0, 1)">
</span><span style="color: rgba(0, 128, 128, 1)"> 7</span> registry = <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">git://mirrors.ustc.edu.cn/crates.io-index</span><span style="color: rgba(128, 0, 0, 1)">"</span>
<span style="color: rgba(0, 128, 128, 1)"> 8</span> <span style="color: rgba(0, 0, 0, 1)">EOF
</span><span style="color: rgba(0, 128, 128, 1)"> 9</span>
<span style="color: rgba(0, 128, 128, 1)">10</span> <span style="color: rgba(0, 0, 0, 1)"># 因为代码提示racer的一些#future功能不能在稳定版使用,无法安装
</span><span style="color: rgba(0, 128, 128, 1)">11</span> <span style="color: rgba(0, 0, 0, 1)"># 所以安装nightly版本的rust 并设置默认版本
</span><span style="color: rgba(0, 128, 128, 1)">12</span> rustup <span style="color: rgba(0, 0, 255, 1)">install</span><span style="color: rgba(0, 0, 0, 1)"> nightly
</span><span style="color: rgba(0, 128, 128, 1)">13</span> <span style="color: rgba(0, 0, 0, 1)">rustup default nightly
</span><span style="color: rgba(0, 128, 128, 1)">14</span>
<span style="color: rgba(0, 128, 128, 1)">15</span> <span style="color: rgba(0, 0, 0, 1)"># 安装RLS组建
</span><span style="color: rgba(0, 128, 128, 1)">16</span> rustup component add rls --<span style="color: rgba(0, 0, 0, 1)">toolchain nightly
</span><span style="color: rgba(0, 128, 128, 1)">17</span> rustup component add rust-analysis --<span style="color: rgba(0, 0, 0, 1)">toolchain nightly
</span><span style="color: rgba(0, 128, 128, 1)">18</span> rustup component add rust-src --<span style="color: rgba(0, 0, 0, 1)">toolchain nightly
</span><span style="color: rgba(0, 128, 128, 1)">19</span>
<span style="color: rgba(0, 128, 128, 1)">20</span> <span style="color: rgba(0, 0, 0, 1)"># 安装racer
</span><span style="color: rgba(0, 128, 128, 1)">21</span> cargo <span style="color: rgba(0, 0, 255, 1)">install</span> racer</pre>
</div>
<p>&nbsp;</p>
<p>windows的安装大致类似,最重要的一点是必须安装Microsoft Visual C++ Build Tools 2015&nbsp;或以上的版本,安装占用至少5GB以上,所以还是linux好一点。</p>
<p>&nbsp;</p>
<div>二、IDE的安装</div>
<div>推荐使用vscode:https://code.visualstudio.com/</div>
<div>安装好vscode后,Ctrl + Shift + X 打开应用商店</div>
<div>搜索chinese安装中文语言包,搜索Rust (rls)官方的插件,基本上就OK可以撸代码了,vscode 的其他配置,自行琢磨折腾吧。</div>
</div><br><br>
来源:https://www.cnblogs.com/honyer/p/11877145.html
頁: [1]
查看完整版本: ubuntu安装rust开发环境