Hostwinds Tutorials
Search results for:
Table of Contents
Tags: Linux, Cloud Servers, VPS
Unlike popular languages like C and Python, which have GCC and CPython bundled in most Linux releases, Rust does not (yet) have native support on Linux and must be installed separately.
This guide will help if you want to install the Rust development toolchain. You'll need a Linux host with shell access to get started.
# export RUSTUP_HOME='~/.rustup'
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Current installation options:
default host triple: x86_64-unknown-Linux-gnu
default toolchain: stable
profile: default
modify PATH variable: yes
To proceed with the default Rust installation, type 1 when prompted, and press Enter. If you want to modify PATH variables, change the toolchain stream, or add a profile, you can select 2 and provide custom values for each.
# source ~/.bash_profile
Rust comes with separate profiles that control which Rust tools are installed in the current environment. The default profile is selected during the installation. You can change profiles at any time
# rustup set profile minimal
# which rustc /root/.cargo/bin/rustc
rustc utilizes the GCC linker for the linking stage of compilation. Your host may or may not have cc available. You can install build-essential the following way:
Distro
Command
RHEL / CentOS / Amazon Linux
sudo yum install gcc gcc-c++ make
Ubuntu / Debian
sudo apt-get install build-essential
Fedora
sudo yum install make gcc gcc-c++ kernel-devel
At this point, the Rust toolchain has been installed and is ready to use. You can test the Rust toolchain by compiling and executing a test Rust program:
# echo -e 'fn main() {\n\tprintln!("Hello from Hostwinds!");\n}' >> hellorust.rs
# cat hellorust.rs
fn main() {
println!("Hello from Hostwinds!");
}
# rustc hellorust.rs
The compiler should output a single file named 'hellorust' which is a compiled binary of the hellorust.rs program:
# file hellorust
hellorust: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=b7a1b1e072fb63c7be826f7964636d6a3b628485, with debug_info, not stripped, too many notes (256)
You can now execute your compiled rust program:
# ./hellorust
Hello from Hostwinds!
Written by Hostwinds Team / June 11, 2021