So you have eventually decided to learn Rust, welcome to the community, brother. Now you have to get a proper developer environment with the best toolings and environment setup for an amazing experience
Let's start with the elephant in the room, “the language’s compiler and its toolings”
To compile Rust code, you must have the rustc compiler, Also, this is not C where you build all your tooling yourself; we have rustup and cargo, even clippy.
Let’s go through each of them.
Cargo
Cargo is like uv or pip or npm, but better. Cargo helps with building your project, running tests, managing your dependencies, and project type, structure, and managing your project. The capabilities of cargo are numerous.
Clippy
Clippy is a tool for ensuring you, as a developer, do not make some syntax-critical errors, like naming conventions, etc.
Rustup
This is the package manager for your rustc compiler, as it helps to update your compiler, add more toolchains for different architectures, and switch toolchains as its most basic functions. Take it like your PM, but for the compiler.
Installing Rust and its toolchain.
Rust makes this super easy for anyone, with one single command or installer package (for Windows), you would have all the necessary tools for working with Rust.
Visit the official website to begin. This would take you to a page for installing the official tooling for Rust.
Now, do well to read through that page before taking even my next advised actions, so you have a better understanding of what is going on; however, in general terms, it is just an installation menu guide.
Follow the instructions on the website to install Rust
For Linux users, run:
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
For Windows users, you should see an installer .exe
file on the website. Go ahead and download this.
For both users, running your tools would open a terminal, and after some time, you might be asked some settings for the download path and some other rustc settings, just go with the default.
Now wait for some time, let the installation finish. When the installation is done, you will see a message on the terminal window stating installation of Rust has completed.
Only now, can you close that terminal and maybe every other shell you have (this is based on your device types, as some OS's would not update the path until every shell is restarted) and restart a shell to check if Rust was installed properly
Run this command to confirm
rustc --version
cargo --version
cargo clippy --version
rustup --version
If you see messages like this. Then, congratulations, you have successfully installed Rust.
Setting up your IDE or Editor (Optional)
If you are not new to programming, well, you can just go ahead and install rust-analyzer on your existing IDE and call this a day.
Now you need to install an IDE. There are a couple of known IDEs out there, with VS Code being the most popular, and if this is your first time, you might want to start with VS Code.
Even though it might be slower than some other IDES dedicated to Rust, it is free and easiest to use and understand with the best tooling support, because, of course, it is powered by Microsoft.
Installing VS Code and setting up some necessary extensions.
To install VS Code as a Windows user:
Go to the official website:
Click on download VS Code -- the large button staring at you.
And run the installer package.
As a Linux or Mac user:
Download the correct packages for your distribution.
Run the native installers based on your machine
Installing from snap
As a Linux user, you may be able to install from the snap package installer if your distribution allows it.
All you need is to run
sudo snap install --classic code
Now you have VS Code installed, let's create a small project so we can see some basic handling of VS Code.
Start a new Binary and install the official Rust analyzer extension
Start the VS Code App by clicking on its icon
Press
Ctrl + J
to open the internal terminalRun the following command in the terminal to start a simple new project
cargo new hello
cd
directory to the hello directory by running
cd hello
Run and build the project by running
cargo run
Reviewing the main.rs file and downloading the analyzer extension
Now, if you look into the file editor, you would notice a main.rs
file. This file is the main file for Rust and where compilation starts.
Open this file, and try looking over what you have got. For now, it should be a main
function with a println!("Hello World!)
in it -- this was generated as template code by Cargo for you.
If you try updating anything in this code, you would notice, you do not get any helpful suggestions, so how do you fix this? To fix this, install the rust-analyzer
extension.
This extension would help you with every single part of your dev experience with Rust.
To install it, open the extension bar on the left side of the screen.
Enter the search bar and search for "rust analyzer", once that has been done, you should see an extension after its name.
Make sure you download only the most popular one, with a verified tick from "The Rust Programming Language", which should be the original.
Looks something like this
Click on it and click
install
Once the extension is installed. Look down the bottom of your VS Code, and you should see it initializing the current directory because it is a valid Rust project.
Once this is completed, go back to your main.rs file and try editing anything, and you should now be getting full intellisense support.
Other Notable IDEs (Zed & Rust Rover, etc)
ZED
The zed IDE is one of the most notable Rust IDEs out there, with over 2k stars, and being natively built in Rust, it is a game-changer.
Setting it up is quite easy; visit their home page and run the installation.
Once that has been done, the IDE would automatically download the necessary tooling like the Rust analyzer.
It comes backed in with AI support, it is free, and is also known to be the fastest IDE, thanks to that GPUI.
JetBrains Rust Rover
This is also a widely used tool with great support and tools, arguably a better experience since it was built specifically for Rust, however, it is only free for non-commercial use.
Check out their website to learn more
Summary
Now you have your IDE, rust toolchain, and some simple template project setup, if you have not already learnt the language, we offer a concise, comprehensible course on Rust. You might want to check that out.
If you had any issues setting this up, it is OK to reach out to me on LinkedIn
Adios Mi Amigos