Easy Tutorial
❮ Rust Collection String Rust Error Handle ❯

Rust Environment Setup

Rust supports many integrated development environments (IDEs) or development-specific text editors.

The official website lists the supported tools as follows (https://www.rust-lang.org/zh-CN/tools):

This tutorial will use Visual Studio Code as our development environment (Eclipse has a dedicated version for Rust development, which is also a good choice for beginners).

Note: After installing the plugin, IntelliJ IDEA is difficult to debug, so developers who are used to using IDEA are recommended to use CLion, but CLion is not free.

Setting Up the Visual Studio Code Development Environment

First, you need to install the latest version of the Rust compiler tools and Visual Studio Code.

Rust compiler tools: https://www.rust-lang.org/zh-CN/tools/install

Visual Studio Code: https://code.visualstudio.com/Download

The Rust compiler tools depend on the C language compiler tools, which means your computer must already have a C language compiler environment. If you are using a Linux system, you often already have GCC or clang. If you are using macOS, you need to install Xcode. If you are using the Windows operating system, you need to install Visual Studio 2013 or later (with C/C++ support) to use MSVC or install the MinGW + GCC compiler environment (Cygwin has not been tested).

Installing Rust Compiler Tools

It is recommended to use Rustup downloaded from the link above to install the Rust compiler tools. The downloaded Rustup is an executable program rustup-init.exe on Windows (on other platforms it should be rustup-init.sh).

Now execute the rustup-init file:

The image above shows a command-line installation wizard.

If you have already installed MSVC (recommended), the installation process will be very simple. Just enter 1 and press Enter to proceed to the next step.

If you have installed MinGW, you need to enter 2 (custom installation), and then the system will ask you "Default host triple?". Please change "msvc" to "gnu" in the default host triple in the image above and then enter it into the installation program:

Other properties are default.

After setting all options, you will return to the installation wizard interface (the first image), where we just need to enter 1 and press Enter.

By this step, the installation of Rust is complete, and you can test it with the following commands:

rustc -V        # Note the uppercase V

If the above two commands can output the version number you installed, the installation is successful.

Setting Up the Visual Studio Code Development Environment

After downloading the Visual Studio Code installation package, start the installation wizard (this step is not detailed here).

After installing Visual Studio Code (referred to as VSCode below), run VSCode.

In the sidebar, find "Extensions" and search for "Chinese" to install the Simplified Chinese extension to make the interface Chinese. (If you prefer an English interface or your computer does not support Chinese characters, this step can be skipped).

Install the rust-analyzer and Native Debug extensions in the same way.

Restart VSCode, and the Rust development environment is set up.

Now create a new folder, such as tutorialpro-greeting.

Open the new folder in VSCode:

After opening the folder, select "Terminal" - "New Terminal" in the menu bar to open a new terminal:

Enter the command in the terminal:

cargo new greeting

A Rust project directory named greeting will be constructed under the current file.

Now enter the following three commands in the terminal:

cd ./greeting
cargo build
cargo run

The system will generate a Hello, world source program main.rs when creating the project, which will be compiled and run at this time:

By this point, you have successfully built a Rust command-line program!

For debugging programs in VSCode, see Cargo Tutorial.

❮ Rust Collection String Rust Error Handle ❯