如何在 Linux 中安装 Rust 编程语言

Rust 通常被称为 rust-lang。Rust 是一个由 Mozilla Research 赞助的通用的、多范式、现代的、跨平台和开源系统编程语言

它旨在实现安全性速度和并发性等目标。

Rust 在语法上与 C++ 相似,但它的设计者希望它在保持性能的同时提供更好的内存安全性。

Rust 目前在许多组织中使用,例如 Firefox、Chef、Dropbox、Oracle、GNOME 等。

如何在 Linux 中安装 Rust 语言?

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

  1. $ curl https://sh.rustup.rs -sSf | sh
  2. info: downloading installer
  3. Welcome to Rust!
  4. This will download and install the official compiler for the Rust programming
  5. language,and its package manager,Cargo.
  6. It will add the cargo, rustc, rustup and other commands to Cargo's bin
  7. directory, located at:
  8. /home/linuxidc/.cargo/bin
  9. This path will then be added to your PATH environment variable by modifying the
  10. profile files located at:
  11. /home/linuxidc/.profile
  12. /home/linuxidc/.bash_profile
  13. You can uninstall at any time with rustup self uninstall and these changes will
  14. be reverted.
  15. Current installation options:
  16. default host triple: x86_64-unknown-linux-gnu
  17. default toolchain: stable
  18. modify PATH variable: yes
  19. 1) Proceed with installation (default)
  20. 2) Customize installation
  21. 3) Cancel installation
  22. >1
  23. info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
  24. info: latest update on 2018-12-06, rust version 1.31.0 (abe02cefd 2018-12-04)
  25. info: downloading component 'rustc'
  26. 77.7 MiB / 77.7 MiB (100 %) 1.2 MiB/s ETA: 0 s
  27. info: downloading component 'rust-std'
  28. 54.2 MiB / 54.2 MiB (100 %) 1.2 MiB/s ETA: 0 s
  29. info: downloading component 'cargo'
  30. 4.7 MiB / 4.7 MiB (100 %) 1.2 MiB/s ETA: 0 s
  31. info: downloading component 'rust-docs'
  32. 8.5 MiB / 8.5 MiB (100 %) 1.2 MiB/s ETA: 0 s
  33. info: installing component 'rustc'
  34. info: installing component 'rust-std'
  35. info: installing component 'cargo'
  36. info: installing component 'rust-docs'
  37. info: default toolchain set to 'stable'
  38. stable installed - rustc 1.31.0 (abe02cefd 2018-12-04)
  39. Rust is installed now. Great!
  40. To get started you need Cargo's bin directory ($HOME/.cargo/bin)in your PATH
  41. environment variable.Nexttime you log inthis will be done automatically.
  42. To configure your current shell run source $HOME/.cargo/env

运行以下命令配置当前 shell。

  1. $ source $HOME/.cargo/env

运行以下命令验证已安装的 Rust 版本

  1. $ rustc --version
  2. rustc 1.31.0(abe02cefd 2018-12-04)

如何测试 Rust 编程语言?

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

  1. $ mkdir~/projects
  2. $ cd~/projects
  3. $ mkdir hello_world
  4. $ cd hello_world

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

  1. $ vi2g.rs
  2. fn main(){
  3. println!("Hello, It's 2linuxidc.com - Best Linux Practical Blog!");
  4. }

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

  1. $ rustc 2g.rs

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

  1. $ ls-lh
  2. total 3.9M
  3. -rwxr-xr-x 1 linuxidc linuxidc 3.9MDec1411:092g
  4. -rw-r--r--1 linuxidc linuxidc 86Dec1411:092g.rs

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

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

好了!正常工作了。

将 Rust 更新到最新版本。

  1. $ rustup update
  2. info: syncing channel updates for'stable-x86_64-unknown-linux-gnu'
  3. info: checking forself-updates
  4. stable-x86_64-unknown-linux-gnu unchanged - rustc 1.31.0(abe02cefd 2018-12-04)

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

  1. $ rustup self uninstall

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

  1. $ rm-fr ~/projects

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

栗子博客 软件 如何在 Linux 中安装 Rust 编程语言 https://www.lizi.tw/soft/13064.html

常见问题
  • 1、杰齐1.7仅适用于PHP5.2 2、需Zend支持 3、尽量使用宝塔面板 4、尽量使用Windows 系统,关关对Linux支持不太友好。
查看详情

相关文章

评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务

如何在 Linux 中安装 Rust 编程语言-海报

分享本文封面