Introduction
Rust is a modern programming language that is blazingly fast, memory-efficient, and type-safe. It is a great language for systems programming, and it is used by companies like Mozilla, Dropbox, and Cloudflare.
Raspberry Pi is a low-cost, credit-card-sized computer that plugs into a computer monitor or TV and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to explore computing and to learn how to program in the language of their choice.
In this blog post, we will learn how to get started with Rust on Raspberry Pi. Let's get started.
Prerequisites
In terms of hardware, you will need the following:
- Raspberry Pi 4 (4GB RAM) (already setup with Raspberry Pi OS)
- Keyboard and Mouse
- Monitor or TV
If you haven't already set up your Raspberry Pi, you can follow the instructions in the earlier post-set up Raspberry Pi 4 without an external monitor. If you don't have a Raspberry Pi, you can still follow along using a virtual machine.
Let's ensure that our Raspberry Pi is up-to-date.
gaurav@RPi4:~ $ uname -a
Linux RPi4 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux
gaurav@RPi4:~ $ sudo apt update && sudo apt upgrade -y
[sudo] password for gaurav:
Hit:1 http://archive.raspberrypi.org/debian bullseye InRelease
Hit:2 http://raspbian.raspberrypi.org/raspbian bullseye InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
libfuse2
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Installing Rust
The Rust documentation suggests using a script available for us to install Rust with Rustup and Cargo on Raspberry Pi.
gaurav@RPi4:~ $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer
Welcome to Rust!
This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.
Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:
/home/gaurav/.rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory is located at:
/home/gaurav/.cargo
This can be modified with the CARGO_HOME environment variable.
The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
/home/gaurav/.cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile files located at:
/home/gaurav/.profile
/home/gaurav/.bashrc
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Current installation options:
default host triple: aarch64-unknown-linux-gnu
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1
info: profile set to 'default'
info: default host triple is aarch64-unknown-linux-gnu
info: syncing channel updates for 'stable-aarch64-unknown-linux-gnu'
info: latest update on 2023-06-01, rust version 1.70.0 (90c541806 2023-05-31)
info: downloading component 'cargo'
6.7 MiB / 6.7 MiB (100 %) 1.3 MiB/s in 4s ETA: 0s
info: downloading component 'clippy'
info: downloading component 'rust-docs'
13.6 MiB / 13.6 MiB (100 %) 3.7 MiB/s in 4s ETA: 0s
info: downloading component 'rust-std'
32.8 MiB / 32.8 MiB (100 %) 2.9 MiB/s in 11s ETA: 0s
info: downloading component 'rustc'
75.5 MiB / 75.5 MiB (100 %) 3.4 MiB/s in 24s ETA: 0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
13.6 MiB / 13.6 MiB (100 %) 1.6 MiB/s in 7s ETA: 0s
info: installing component 'rust-std'
32.8 MiB / 32.8 MiB (100 %) 5.8 MiB/s in 5s ETA: 0s
info: installing component 'rustc'
75.5 MiB / 75.5 MiB (100 %) 6.3 MiB/s in 11s ETA: 0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-aarch64-unknown-linux-gnu'
stable-aarch64-unknown-linux-gnu installed - rustc 1.70.0 (90c541806 2023-05-31)
Rust is installed now. Great!
To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).
To configure your current shell, run:
source "$HOME/.cargo/env"
Join the conversation! Your thoughts help the community grow.