Let’s start rust’s learning journey! There is a lot to learn, but just as every journey begins somewhere. In this chapter, we will discuss:
- Install rust on Linux, MacOS, windows
- Write an output
cargo, perform the package management and system compilation of rust
Step 1: install rust. We from
rustup–A command line tool for managing rust versions and associated tools — download rust. You need to connect to the network to download.
Note: if you choose not to pass for various reasons
rustupThe way, then go toRust official websiteSee other ways.
The next steps describe how to install the latest version of the rust compiler. The stability of rust ensures that all examples in this book can be compiled in the latest version of rust. Since rust often improves the output experience of error messages and warning messages, the output of editing results of each version may be slightly different. In other words, any updated, stable version of rust you install will have expected output for the examples in this book.
Command line tag
In this chapter or in various parts of the book, we will show some commands used at the terminal. Everything displayed on the command line will be
$start. You don’t need to enter it manually
$Symbol, which only represents the beginning of each command line. Those who don’t
$The first content line represents the output of the previous command. In addition, special PowerShell examples use
Installing rustup on Linux and MacOS
If you are using Linux or MacOS, please open the terminal and enter the following command
curl https://sh.rustup.rs -sSf | sh
This command will download a script and start the installation of the latest version of the tool ` rustup ‘. You may be prompted to enter a password during installation. If the installation is successful, the following will appear:
Rust is installed now. Great!
If you like, you can check the script content before downloading the script and running it.
The whole installation process will automatically add rust to your system variable path when you log in next time. If you want to start using rust directly without restarting the terminal, please run the following command in the terminal to add rust to your system variable:
Or, add the following to ~ /. Bash_ In profile:
Besides, you need some kind of linker. It is likely that your system has already installed the linker. However, if an error occurs when you try to compile a rust program and you are prompted that the linker is not executed, it means that your system has not installed the linker, and you need to install it manually.
C compilers usually have the correct linker. You can check the documentation of your system to learn how to install the C compiler. of course,
Some common rust packages rely on C language code and often require a C compiler. So you can install it now.
Installing rustup on Windows
In windows, openhttps://www.rust-lang.org/too…, install according to the instructions. During the installation process, you will receive a message that you need to install visual studio 2013 or later C + + build tools. The easiest way to get the build tool is to install itBuild Tools for Visual Studio 2017, the tool can be used in web pages
Other tools and frameworksGet from.
The commands shown in the rest of this book can be found in
PowerShellUsed in. If there are differences for a certain scene, we will clearly point out in the book.
Update and uninstall
When you pass
rustupAfter installing rust, you can easily update the version of rust. Open your terminal and run the following command:
Uninstall rust and
rustup, please run the following uninstall script in your terminal
rustup self uninstall
Open the terminal and enter the following command to check whether you have installed rust correctly
After that, you should see the output version number with the latest stable version, the submission hash value and the submission date. The format is as follows:
rustc x.y.x (abcabcabc yyyy-mm-dd)
If you see the message, you have successfully installed rust. If you don’t see this information, please check whether rust is in your Windows environment
%PATH%In the system variable. If all steps are OK, but rust still doesn’t work properly, you can get help in many places. The easiest way is throughMibbitvisitthe #rust IRC channel on irc.mozilla.org 。 In this place, you can get help by chatting with other rustaceans (our nickname for ourselves). You can also learn fromthe Users forumandStack OverflowGet help.
The installation package contains a copy of the local documentation so that you can read the documentation offline after installation. function
rustup docYou can open a document in the explorer to explore.
At any time, if you don’t know how to use the types or functions provided by the standard library, you can find the corresponding instructions through the API documents.