我们可以通过多种方式安装 Rust,但以下是官方推荐的安装方式。
$ curl https://sh.rustup.rs -sSf | sh
输入命令后控制台输出: root@node_super:~# curl https://sh.rustup.rs -sSf | sh info: downloading installer Welcome to Rust! This will download and install the official compiler for the Rust programming language, and its package manager, Cargo. It will add the cargo, rustc, rustup and other commands to Cargo's bin directory, located at: /root/.cargo/bin This can be modified with the CARGO_HOME environment variable. Rustup metadata and toolchains will be installed into the Rustup home directory, located at: /root/.rustup This can be modified with the RUSTUP_HOME environment variable. This path will then be added to your PATH environment variable by modifying the profile file located at: /root/.profile You can uninstall at any time with rustup self uninstall and these changes will be reverted. Current installation options: default host triple: x86_64-unknown-linux-gnu default toolchain: stable profile: default modify PATH variable: yes 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation > info: profile set to 'default' info: default host triple is x86_64-unknown-linux-gnu info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu' 463.3 KiB / 463.3 KiB (100 %) 94.6 KiB/s in 2s ETA: 0s info: latest update on 2020-03-12, rust version 1.42.0 (b8cedc004 2020-03-09) info: downloading component 'cargo' 4.8 MiB / 4.8 MiB (100 %) 707.4 KiB/s in 7s ETA: 0s info: downloading component 'clippy' 1.8 MiB / 1.8 MiB (100 %) 887.5 KiB/s in 3s ETA: 0s info: downloading component 'rust-docs' 12.0 MiB / 12.0 MiB (100 %) 1.6 MiB/s in 9s ETA: 0s info: downloading component 'rust-std' 17.1 MiB / 17.1 MiB (100 %) 2.5 MiB/s in 8s ETA: 0s info: downloading component 'rustc' 58.6 MiB / 58.6 MiB (100 %) 3.4 MiB/s in 20s ETA: 0s info: downloading component 'rustfmt' 3.0 MiB / 3.0 MiB (100 %) 2.9 MiB/s in 1s ETA: 0s info: installing component 'cargo' info: installing component 'clippy' info: installing component 'rust-docs' 12.0 MiB / 12.0 MiB (100 %) 7.0 MiB/s in 1s ETA: 0s info: installing component 'rust-std' 17.1 MiB / 17.1 MiB (100 %) 10.5 MiB/s in 1s ETA: 0s info: installing component 'rustc' 58.6 MiB / 58.6 MiB (100 %) 8.8 MiB/s in 6s ETA: 0s info: installing component 'rustfmt' info: default toolchain set to 'stable' stable installed - rustc 1.42.0 (b8cedc004 2020-03-09) 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. To configure your current shell run source $HOME/.cargo/env
运行以下命令配置当前 shell。
$ source $HOME/.cargo/env
运行以下命令验证已安装的 Rust 版本。
$ rustc --version
二、运行Rust简单的代码
安装 Rust 后,请按照以下步骤检查 Rust 语言是否正常工作。
mkdir /home/rust/ cd /home/rust/ vim test.rs
写入如下代码
fn main() { println!("Hello, welcome to come Rust!"); }
运行以下命令编译 rust 代码。
rustc test.rs
上面的命令将在同一目录中创建一个可执行的 Rust 程序。
ls -lh
运行 Rust 可执行文件得到输出。
./test Hello, welcome to come Rust!
将 Rust 更新到最新版本。
rustup update
运行以下命令从系统中删除 Rust 包。
rustup self uninstall
关于Rust的安装教程分享结束,大家有疑问可以在评论区留言分享啊。
以上就是
为各位朋友分享的 相关内容。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多