Linux系统如何安装Rust语言

发布时间:2022-01-24 10:40:08 作者:小新
来源:亿速云 阅读:214

这篇文章主要介绍了Linux系统如何安装Rust语言,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

Rust 速度惊人且内存利用率极高。由于没有运行时和垃圾回收,它能够胜任对性能要求特别高的服务,可以在嵌入式设备上运行,还能轻松和其他语言集成。

Rust 语言简介:

Linux 中安装 Rust 语言具体步骤:

我们可以通过多种方式安装 Rust,但以下是官方推荐的安装方式。

 $ 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: 
   /home/daygeek/.cargo/bin 
 This path will then be added to your PATH environment variable by modifying the profile files located at: 
   /home/daygeek/.profile   /home/daygeek/.bash_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   modify PATH variable: yes 
 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation >1 
 info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu' info: latest update on 2018-12-06, rust version 1.31.0 (abe02cefd 2018-12-04) info: downloading component 'rustc'  77.7 MiB /  77.7 MiB (100 %)   1.2 MiB/s ETA:   0 s                 info: downloading component 'rust-std'  54.2 MiB /  54.2 MiB (100 %)   1.2 MiB/s ETA:   0 s                 info: downloading component 'cargo'   4.7 MiB /   4.7 MiB (100 %)   1.2 MiB/s ETA:   0 s                 info: downloading component 'rust-docs'   8.5 MiB /   8.5 MiB (100 %)   1.2 MiB/s ETA:   0 s                 info: installing component 'rustc' info: installing component 'rust-std' info: installing component 'cargo' info: installing component 'rust-docs' info: default toolchain set to 'stable' 
   stable installed - rustc 1.31.0 (abe02cefd 2018-12-04) 
 
 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 rustc 1.31.0 (abe02cefd 2018-12-04)

如何测试 Rust 编程语言?

安装 Rust 后,请按照以下步骤检查 Rust 语言是否正常工作。

 $ mkdir ~/projects $ cd ~/projects $ mkdir hello_world $ cd hello_world

创建一个文件并添加以下代码并保存。确保 Rust 文件始终以 .rs 扩展名结尾。

 $ vi 2g.rs 
 fn main() {  println!("Hello, It's 2DayGeek.com - Best Linux Practical Blog!"); }

运行以下命令编译 rust 代码。

 $ rustc 2g.rs

上面的命令将在同一目录中创建一个可执行的 Rust 程序。

 $ ls -lh total 3.9M -rwxr-xr-x 1 daygeek daygeek 3.9M Dec 14 11:09 2g -rw-r--r-- 1 daygeek daygeek 86 Dec 14 11:09 2g.rs

运行 Rust 可执行文件得到输出。

 $ ./2g Hello, It's 2DayGeek.com - Best Linux Practical Blog!

好了!正常工作了。

将 Rust 更新到最新版本。

 $ rustup update info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu' info: checking for self-updates 
   stable-x86_64-unknown-linux-gnu unchanged - rustc 1.31.0 (abe02cefd 2018-12-04)

运行以下命令从系统中删除 Rust 包。

 $ rustup self uninstall

卸载 Rust 包后,删除 Rust 项目目录。

 $ rm -fr ~/projects

感谢你能够认真阅读完这篇文章,希望小编分享的“Linux系统如何安装Rust语言”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

推荐阅读:
  1. 如何在IntelliJ中安装Rust IDE插件
  2. Rust能不能代替C语言

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

linux rust

上一篇:U盘如何启动安装Linux系统

下一篇:正则表达式基础命令有哪些

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》