ubuntu rust_如何在Ubuntu Linux上安装Rust
ubuntu rust
Today we’ll learn how to install Rust on Ubuntu Linux. The Rust programming language, more commonly known as rust-lang, is a powerful general-purpose programming language.
今天,我们将学习如何在Ubuntu Linux上安装Rust。 Rust编程语言(通常称为rust-lang)是一种功能强大的通用编程语言。
Developed by Mozilla and designed by Graydon Hoare, this programming language is syntactically similar to C++.
该编程语言由Mozilla开发,由Graydon Hoare设计,在语法上类似于C ++ 。
Built on the pillars of data safety, parallelism, and speed, Rust is used for a wide range of software development projects ranging from browser components to game engines and operating systems.
建立在数据安全性,并行性和速度的Struts之上,Rust用于各种软件开发项目,从浏览器组件到游戏引擎和操作系统。
Its ability to be easily integrated seamlessly with other languages means that its user base is expanding with every passing day.
它易于与其他语言无缝集成的能力意味着其用户群日新月异。
从安装开始 (Starting with the Installation)
We made this tutorial on Ubuntu 20.04 (Focal fossa) but the same commands will apply to previous versions and other Linux distributions that are based on Debian/Ubuntu.
我们在Ubuntu 20.04(Focal fossa)上制作了本教程,但是相同的命令将应用于基于Debian / Ubuntu的早期版本和其他Linux发行版。
Before we begin to install Rust on Ubuntu, we might wish to make sure that all our system repositories are up-to-date. To do this, we need to update our default repositories using the apt package management service.
在开始在Ubuntu上安装Rust之前,我们可能希望确保所有系统存储库都是最新的。 为此,我们需要使用apt软件包管理服务更新默认存储库。
To do this, you need to open the terminal on your Ubuntu system and type the following.
为此,您需要在Ubuntu系统上打开终端并输入以下内容。
sudo apt update
You should see an output similar to this on your screen. Next, we will use the upgrade command in our terminal
您应该在屏幕上看到类似的输出。 接下来,我们将在终端中使用upgrade命令
sudo apt upgrade
Enter ‘Y’ in the command line to proceed with the operation. Now, we would have all the updated repositories when we install Rust on Ubuntu Linux.
在命令行中输入“ Y”以继续操作。 现在,在Ubuntu Linux上安装Rust时,我们将拥有所有更新的存储库。
如何在Ubuntu上安装Rust (How to Install Rust on Ubuntu)
Now that we understand the Rust programming language, and have covered the prerequisites, it is time to install Rust on Ubuntu. To do so, you need to follow the following steps.
既然我们了解了Rust编程语言,并且已经满足了前提条件,现在该在Ubuntu上安装Rust了。 为此,您需要遵循以下步骤。
使用RustUp脚本在Ubuntu上安装Rust (Install Rust on Ubuntu using the RustUp Script)
While there are several different ways to install Rust on Linux, the most recommended method is using the rustup shell script.
尽管有几种不同的方法可以在Linux上安装Rust,但是最推荐的方法是使用rustup shell脚本。
This is the recommended way to install Rust on Ubuntu on the official Rust website. So this would be the method we will be using in this tutorial. To use the rustup installer, we need to enter the following command in our terminal.
建议在官方Rust网站上的Ubuntu上安装Rust的推荐方法。 所以这就是我们将在本教程中使用的方法。 要使用rustup安装程序,我们需要在终端中输入以下命令。
curl https://sh.rustup.rs -sSf | sh
When you run this command, you should see a screen similar to the output shown above. You will be given the option to choose the type of installation you wish to choose.
运行此命令时,应该会看到类似于上述显示的屏幕。 您将可以选择要选择的安装类型。
If you are familiar with the rustup installer and wish to customize your installation, choose the second option. However, for the sake of this tutorial, we will simply choose the default first option and press enter.
如果您熟悉rustup安装程序并希望自定义安装,请选择第二个选项。 但是,出于本教程的考虑,我们仅选择默认的第一个选项,然后按Enter。
Now, we will configure our current shell using the following command.
现在,我们将使用以下命令配置当前的shell。
source $HOME/.cargo/env
验证安装 (Verifying the installation)
Once we install Rust on Linux, we need to verify the installation before we can start using Rust on our system.
在Linux上安装Rust之后,我们需要先验证安装情况,然后才能在系统上开始使用Rust。
We can verify this by asking the terminal for the version of the Rust programming language on our system. To do so, we enter this in our terminal.
我们可以通过询问终端系统上的Rust编程语言的版本来验证这一点。 为此,我们在终端中输入。
rustc --version
This will fetch the version of the Rust programming language on our system. At the time of making this tutorial, the latest available stable release of Rust is version 1.43.1 as seen in the screenshot below.
这将在我们的系统上获取Rust编程语言的版本。 在撰写本教程时,Rust的最新可用稳定版本是1.43.1版本,如下面的屏幕快照所示。
Now, we will test if Rust is working properly. To do so, we will first create some directories for our Rust scripts using the following commands.
现在,我们将测试Rust是否正常运行。 为此,我们将首先使用以下命令为Rust脚本创建一些目录。
mkdir ~/rustprojects
cd ~/rustprojects
mkdir testdir
cd testdir
This will create a directory for our Rust projects and another test directory within the project directory. Now we will create a file to store our Rust code using nano or any of your preferred text editors.
这将为我们的Rust项目创建一个目录,并在项目目录中创建另一个测试目录。 现在,我们将使用nano或您喜欢的任何文本编辑器创建一个文件来存储Rust代码。
nano rusttestfile.rs
Note that you must use the .rs extension for all your Rust scripts. When te file is opened, enter the following test code and save the file.
请注意,您必须对所有Rust脚本使用.rs扩展名。 打开文件时,输入以下测试代码并保存文件。
fn main() {
println!("Congrats! Your Rust script is running");
}
Now, we will compile the code using the rustc command and then create a rust executable in the same directory. Now, let us run the executable file using the following command. If we did everything correctly, we should expect to see an output like the one above.
现在,我们将使用rustc命令编译代码,然后在同一目录中创建rust可执行文件。 现在,让我们使用以下命令运行可执行文件。 如果我们正确地完成了所有操作,则应该期望看到与上述输出类似的输出。
If your test script is working, you were successful to install Rust on Ubuntu. Now, you can proceed to work on developing software and scripts using the Rust programming language.
如果您的测试脚本有效,则可以成功在Ubuntu上安装Rust。 现在,您可以继续使用Rust编程语言来开发软件和脚本。
其他常用的Rust命令 (Other commonly used Rust commands)
We have covered the steps to install Rust on Ubuntu. But there are still two commands to discuss that would be useful to you. Over regular intervals, you should update your installation of Rust on Linux.
我们已经介绍了在Ubuntu上安装Rust的步骤。 但是仍然有两个要讨论的命令对您有用。 请定期在Linux上更新Rust的安装。
This is important to ensure that you have access to the latest features and functionalities of rust on your system. To do so, enter the following command in your terminal.
这对于确保您可以访问系统上最新的防锈功能非常重要。 为此,请在终端中输入以下命令。
rustup update
In the event that you no longer wish to use Rust on your system, you can choose to uninstall it. To remove Rust from your system along with its associated repositories, you need to use this command.
如果您不再希望在系统上使用Rust,则可以选择卸载它。 要从系统及其关联的存储库中删除Rust,您需要使用此命令。
rustup self uninstall
结论 (Conclusion)
Rust is a multi-paradigm programming language. It was created as a language designed to create programs that are powerful and efficient. Its open-source nature, support from Mozilla, and a dedicated community are just a few reasons why it is being adopted by more and more developers over time.
Rust是一种多范式编程语言。 它被创建为旨在创建功能强大且高效的程序的语言。 它的开源性质,Mozilla的支持以及一个专门的社区只是随着时间的推移越来越被越来越多的开发人员采用它的几个原因。
We hope this tutorial was able to help you install Rust on Ubuntu. If you have any feedback, queries or suggestions, feel free to reach out to us in the comments below.
我们希望本教程能够帮助您在Ubuntu上安装Rust。 如果您有任何反馈,疑问或建议,请随时通过以下评论与我们联系。
翻译自: https://www.journaldev.com/39960/install-rust-on-ubuntu-linux
ubuntu rust
更多推荐
所有评论(0)