Skip to main content

Install Rust on CentOS 7 Or Ubuntu22.04 / Macos

Rust
KIGA
Author
KIGA
This is a personal blog, intended for sharing.
Table of Contents

Macos
#

https://www.rust-lang.org/tools/install

Centos 7
#

Note: Before installing Rust, make sure that the system has installed C and C++ compilers, as well as other necessary dependencies. You can use the following command to install these dependencies:

sudo yum install -y gcc gcc-c++ make openssl-devel

Open a terminal and update the system:
#

sudo yum update

Install Rust:
#

curl https://sh.rustup.rs -sSf | sh

This command will download and run the Rust installation script. During the installation process, you will be prompted to choose the default options or customize the installation as needed.

Configure the Rust environment variables:
#

After Rust is installed, you need to add the Rust binary file path to the system’s PATH environment variable. You can use the following command to add the Rust binary file path to the PATH environment variable:

source $HOME/.cargo/env

Verify that Rust is installed successfully:
#

You can use the following command to verify that Rust is installed successfully:

rustc --version

small exercise
#

install exercise tool manually

git clone -b 5.6.1 --depth 1 https://github.com/rust-lang/rustlings
cd rustlings
cargo install --force --path .

doing exercises with rustlings

rustlings watch
# rustlings run myuExercise
# rustlings hint myExercise
# ruslings verify
# rustlings list

uninstalling rustlings

cargo uninstall rustlings

Ubuntu22.04
#

To install Rust on Ubuntu 22.04, you can use rustup, which is the recommended way to install the Rust programming language. Here are the steps:

  1. First, download and install rustup by running the following command in your terminal:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. The above command will download a script and start the installation. You will be prompted to proceed with the installation. Press “1” and then “Enter” to proceed with the default installation.

  2. Once the installation is complete, close the terminal and open a new one.

  3. Add the cargo and rustc binaries to your PATH with the following command:

source $HOME/.cargo/env
  1. Verify the installation by running the following command:
rustc --version

This should display the installed version of Rust.

Run the source $HOME/.cargo/env command in every new terminal you open or add the command to your .bashrc or .zshrc file to automatically set the PATH for every new terminal session.

Errors may Occur
#

The error “linker cc not found” typically means that the C compiler is not installed on your system. Rust needs the C compiler for linking.

On Ubuntu, you can install the C compiler (gcc) by installing the build-essential package. This package also includes other tools that are necessary for building software.

You can install it by running the following command in your terminal:

sudo apt update
sudo apt install build-essential
sudo apt-get install manpages-dev

After the installation is complete, you should be able to compile your Rust program. If you still encounter the same error, you might need to restart your terminal or your computer for the changes to take effect.