Ubuntu上安装Rust
使用Ubuntu系统,我们通过rustup工具来下载和安装Rust。rustup是一个命令行工具,用于管理Rust版本和其他Rust相关工具。
安装rustup(命令行中的首$符表示终端的提示符,不需要拷贝到终端中执行):
$ curl https://sh.rustup.rs -sSf | sh
下载开始后会出现欢迎界面
Welcome to Rust!
并告知将开始下载和安装Rust官方编译器与包管理器Cargo,cargo、rustc、rustup和其他相关命令都会添加到Cargo的bin目录下,并且添加到用户环境变量中。
继续往下会提示选择安装方式:
1 ) Proceed with installation (default)
2 ) Customize installation
3 ) Cancel installation
这里我选择1,使用默认安装方式
终端输出一顿下载操作后,显示如下:
stable installed - rustc 1.36.0 (a53f9df32 2019-07-03)
Rust is installed now. Great!
To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH
environment variable. Next time you log in this will be done automatically.
Rust安装完成,rustc版本为1.36.0,整个过程非常简单!
按照它的提示,重启shell或执行
$ source $HOME/.cargo/env
将使Rust添加的环境变量生效。
然而我重启shell后rustc仍然提示找不到rustc,需要将$HOME/.cargo/bin目录手动添加到~/.bashrc文件末尾。
export PATH=$PATH:$HOME/.cargo/bin
重启shell或执行source ~/.bashrc,尝试查看rustc版本号:
$ rustc --version
rustc 1.36.0 (a53f9df32 2019-07-03)
后续要升级Rustc可以直接使用命令
$ rustup update
本地查看rust文档
$ rustup doc
网友评论