This article introduces the configuration of Rust+VS Code development environment on Windows and Linux.
Windows
Install
In fact, installing Rust on Linux is easy by comparison. The process for Windows is tedious.
Download the rust installation package from this website: Rust
The installation process will be performed by terminal printing. Rust currently does not have a graphical installation process on Windows.
Rust needs to install two things, one is rustup and the other is cargo. These two will be installed on the C drive by default. If you do not want Rust to be installed on the C drive, you need to set the environment variable in advance.
-
By
RUSTUP_HOME
specifying the directory where rustup is installed.
-
By
CARGO_HOME
specifying the directory where cargo is installed.
Ready to install.
Rust requires a computer with a C++ compiler, and it is recommended to use the default MSVC under Windows. If you want to change to GNU, you need to chooseCustomize installation
. Of course, I don't recommend changing to GNU, because there will be many inexplicable bugs.
After installation, enter the following command in the terminal to verify that Rust is installed successfully:
rustc -V
Verify that cargo is installed successfully:
cargo -V
Configure VS Code
First install this extension: rust-analyzer
Create new rust project:
cargo new HelloWorld
Open the folder with VS Code
and click "Run" to compile and run the rust project
Linux(Ubuntu 20.04 LTS)
I don't have a dual system, so I will use WSL as an example to demonstrate the Rust installation.
Install
Just two lines of command:
sudo apt install rustc
sudo apt install cargo
Of course, the environment needs gcc, you can check it
gcc -v
Configure VS Code
same order
cargo new HelloRust
Switch and open with VS Code.
I don’t know why, but the rust-analyzer plugin under WSL doesn’t work properly.
So I can only use the terminal to execute the command instead, and I will look for the reason later:
cargo run