Install Rust on Linux#
During my journey to learn Rust, I will be sharing some steps with you. This time, let’s cover how to install Rust on Linux and prepare ourselves to use it in VSCode and Notebook.
Rust is a low-level language developed with Mozilla’s support, focused on performance and security, with excellent compile-time checks that help prevent some runtime errors. By design, it aims for better ergonomics than a low-level language while still allowing for greater control.
Install with Rustup#
The recommended installation is via the tool rustup, for this we proceed with
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
This downloads rustup, and initiates the installation process for Rust and other utilities. There, we can accept the default option by pressing enter.
Thus, we will have installed cargo
(the
package manager of Rust), clippy
(the
integrated linter for Rust), rust-docs
(Rust documentation),
rust-std
(the standard library of Rust),
rustc
(the Rust
compiler), and rustfmt
(the code
formatter for Rust). And of course, the same
rustup
that allows us to manage the
toolchain of Rust.
Regarding cargo, there is something interesting to mention: it
integrates the execution of tests (cargo test
), which is also an option of the
compiler, and the generation of documentation (cargo doc
) with
rustdoc
.
Now we conclude with
source "$HOME/.cargo/env"
This allows us to associate the necessary environment variables in the current console.
If now we execute rustc --version
, we should see the compiler version. If you
don’t see it, you may have skipped the previous step for associating the
environment variable.
When we want to update the compiler version, we will use rustup update
.
Configure VSCode#
To have the necessary help in our IDE, VSCode, while programming in Rust, we are going to install the extension rust-analyzer. This extension provides options for autocompletion, go to definition, find references, access documentation, semantic highlighting, assistance, and suggestions. All of this is a benefit thanks to the implementation of the LSP (Language Server Protocol) for Rust.
Rust Analyzer is also available for other editors.
We can start with a small default project to see the extension in action, as well as our base installation. To create a new one, we use
cargo new miniproject
This creates a basic Rust application project template, including Cargo dependency files and a source directory with a “hello world” example. We can use some basic erroneous code to see it in action.
Rust Notebook#
Now, we have the option to add a Rust kernel to Jupyter Notebook for an interactive Rust experience combined with the benefit of naturally documenting code. This can be achieved thanks to the kernel Evcxr.
First, we install the necessary dependency with cargo.
cargo install --locked evcxr_jupyter
Once installed, we should ensure that our Jupyter Notebook environment is active (in case it’s in a specific environment). If Jupyter Notebook is not already installed, on Ubuntu we can proceed as follows:
sudo apt install -y jupyter-notebook
Or with the Python package manager (installing notebook
and jupyterlab
),
like so:
pip install notebook jupyterlab # With PIP
uv pip install notebook jupyterlab # With UV
Now, let’s add the Kernel to Notebook.
evcxr_jupyter --install
Once added, we can open Notebook or JupyterLab, and we will see the option to use Rust.
jupyter notebook # Open notebook
jupyter lab # Open Jupyterlab (recommended)