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

Rust(俗称Rust-Lang)是一种相对较新的开源实用系统编程语言,运行速度极快,可防止段错误,并保证线程安全。 它是由Mozilla开发并由LLVM支持的安全并发语言。

它支持零成本抽象,移动语义,保证内存安全,没有数据争用的线程,基于特征的泛型和模式匹配。 它还支持类型推断,最小运行时以及高效的C绑定。

Rust可以在很多平台上运行,并且正在被Dropbox,CoreOS,NPM等公司/组织用于生产。

在本文中,我们将展示如何在Linux中安装Rust编程语言并设置系统以开始编写带有Rust的程序。

在Linux中安装Rust编程语言

要安装Rust,请使用以下官方方法通过installer-script安装rust,这需要curl命令行下载,如图所示。

然后通过在终端中运行以下命令来安装Rust,并按照屏幕上的说明进行操作。请注意,实际安装了Rust,并且由Rust工具管理。

示例:

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:

扫描二维码关注公众号,回复: 5417468 查看本文章

This path will then be added to your PATH environment variable by modifying the
profile file located at:

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

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

在Linux中安装Rust

>1

info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
320.9 KiB / 320.9 KiB (100 %) 254.7 KiB/s ETA:  0 s               
info: latest update on 2019-02-28, rust version 1.33.0 (2aa4c46cf 2019-02-28)
info: downloading component 'rustc'
 66.7 MiB /  84.7 MiB ( 79 %)  19.2 KiB/s ETA: 963 s                     
 70.9 MiB /  84.7 MiB ( 84 %)  19.2 KiB/s ETA: 738 s                     
 71.0 MiB /  84.7 MiB ( 84 %)  19.2 KiB/s ETA: 735 s               
 71.0 MiB /  84.7 MiB ( 84 %)  19.2 KiB/s ETA: 734 s               


 84.7 MiB /  84.7 MiB (100 %)  76.8 KiB/s ETA:  0 s               
info: downloading component 'rust-std'
 35.5 MiB /  56.8 MiB ( 62 %)  41.6 KiB/s ETA: 525 s                     
 56.8 MiB /  56.8 MiB (100 %)  99.2 KiB/s ETA:  0 s               
info: downloading component 'cargo'
  4.4 MiB /  4.4 MiB (100 %)  44.8 KiB/s ETA:  0 s               
info: downloading component 'rust-docs'
  8.5 MiB /  8.5 MiB (100 %)  67.2 KiB/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.33.0 (2aa4c46cf 2019-02-28)


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

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

在Linux中安装Rust

Rust安装完成后,Cargo的bin目录(~/.cargo/bin - 安装了所有工具)将添加到PATH环境变量~/.profile中。

在安装过程中,rustup会尝试将cargo的bin目录添加到PATH中;如果由于某种原因失败,请手动操作以开始使用Rust。

将Rust Cargo Bin目录添加到PATH

将Rust Cargo Bin目录添加到PATH

接下来,使用修改后的PATH来源~/.profile文件,并通过运行这些命令配置当前shell以使用Rust环境。

最后,运行以下命令验证系统上安装的Rust的版本。

 检查在Linux中安装的Rust版本

检查在Linux中安装的Rust版本

在Linux中测试Rust编程语言

现在您已经在系统上安装了Rust,您可以通过创建第一个Rust程序来测试它,如下所示。首先创建一个程序文件所在的目录。

最后,如图所示执行测试。

用Rust语言编写程序

用Rust语言编写程序

重要提示:您应该注意有关Rust发布的这些要点:

  • 必须有一个为期6周的快速发布过程,确保随时可以获得许多Rust。
  • 其次,所有这些构建都通过在每个支持的平台上以一致的方式进行Rust来管理,从而允许从beta和夜间释放通道安装Rust,并支持其他交叉编译目标。

Rust主页:https://www.rust-lang.org/en-US/

在本文中,我们已经解释了如何在Linux中安装和使用Rust编程语言。试试看,并通过下面的留言提供您的反馈或分享任何疑问。

下面关于Rust的文章您也可能喜欢,不妨参考下:

Rust 的详细介绍请点这里
Rust 的下载地址请点这里

猜你喜欢

转载自www.linuxidc.com/Linux/2019-03/157229.htm