How to set up a Rust environment on Linux
Start your Rust development journey by setting up a Rust development environment on your Linux PC. Here are detailed instructions.
According to Stack Overflow's Developer Survey 2022, Rust has become the most popular programming language for the past 7 years. It is secure, efficient and flexible to handle applications of all levels of complexity, from system programming to chatbots and more.
If you haven't had a chance to start developing in Rust yet, you should start by setting up a Rust development environment on Linux.
Rust installation required on Linux
Before installing Rust, you need to install a dependency: the build-essential package. Why? Because Rust needs a link to link all the object files produced by the Rust compiler into an executable binary. The build-essential package contains a linker that will get the job done.
Here is the command to install the build-essential package on Linux:
sudo apt update && sudo apt install build-essential
For Arch Linux, run:
sudo pacman -S base-devel
Once you've finished installing this package, move on to installing Rust.
Install Rust on Linux
Rust is super easy to install and set up. All you need to do is run a single script. It will install and set everything up for you.
The best thing is that the official Rust developer has developed this script strictly, so you can't run suspicious software on the system.
Here is the command to install and run the rustup script:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
This command will use curl to load the script and run it using sh. Enter 1 when prompted.
After a while, the script will complete the task and ask you to update the PATH variable to include the Cargo bin directory. You can do that with the source command:
source "$HOME/.cargo/env"
Setting up and writing 'Hello, World' in Rust
Rust's build system, Cargo is a resourceful tool that helps you get up and running, organize, and test your code with a few lines of command. To set up a new Rust project, run this command:
cargo new
This command will set up a directory structure for the base project and add the main.rs file containing the code for the 'Hello, World' program inside //src . You can manually compile this code with compiler rustc or use Cargo to run it:
cargo run
Also, here's the syntax for using rustc to manually compile the code:
rustc main.rs ./a
Now that you have Rust installed and set up on your Linux system, you can focus on learning and developing all kinds of programs with Rust right away.
You should read it
- What is Unsafe Rust?
- Ways to handle errors in Rust
- Things to know about Fearless Concurrency in Rust
- Documenting a Rust project with mdBook
- How to mine and fetch data using Rust
- Rust - interesting programming language worth learning
- How to containerize a Rust app with Docker
- Top 3 Roblox games like Rust
- Rust - A programming language created by a broken elevator, can 'surpass' both C and C ++
- Asynchronous Programming in Rust
- Microsoft officially announced the Rust / WinRT project on GitHub
- Why the Rust programming language will be the future of programming