Fail to run cargo after install rust on raspberry pi 4

3.3k Views Asked by At

I was trying to install rust on Raspberrypi 4 using the recommended install script:

pi@raspberrypi:/tmp $ curl https://sh.rustup.rs -sSf | sh

But after reboot, cargo cannot be found:

pi@raspberrypi:~ $ cargo
error: command failed: 'cargo'
error: caused by: No such file or directory (os error 2)

This may have to do with (error reading rustc version) reported during installation (full installation log at the bottom):

info: default toolchain set to 'stable-aarch64-unknown-linux-gnu'

  stable-aarch64-unknown-linux-gnu installed - (error reading rustc version)

Here are full install logs:

pi@raspberrypi:/tmp $ curl https://sh.rustup.rs -sSf | 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/pi/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory located at:

  /home/pi/.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/pi/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /home/pi/.profile
  /home/pi/.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 2021-03-25, rust version 1.51.0 (2fd73fabe 2021-03-23)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
 15.0 MiB /  15.0 MiB (100 %)   6.6 MiB/s in  2s ETA:  0s
info: downloading component 'rust-std'
 26.3 MiB /  26.3 MiB (100 %)  10.2 MiB/s in  4s ETA:  0s
info: downloading component 'rustc'
 76.9 MiB /  76.9 MiB (100 %)  10.1 MiB/s in 12s ETA:  0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: using up to 500.0 MiB of RAM to unpack components
  5.3 MiB /   5.3 MiB (100 %)   5.1 MiB/s in  1s ETA:  0s
info: installing component 'clippy'
info: installing component 'rust-docs'
 15.0 MiB /  15.0 MiB (100 %)   2.3 MiB/s in  6s ETA:  0s
info: installing component 'rust-std'
 26.3 MiB /  26.3 MiB (100 %)   4.5 MiB/s in  9s ETA:  0s
info: installing component 'rustc'
 76.9 MiB /  76.9 MiB (100 %)   5.0 MiB/s in 15s ETA:  0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-aarch64-unknown-linux-gnu'

  stable-aarch64-unknown-linux-gnu installed - (error reading rustc version)


Rust is installed now. Great!

To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH
environment variable. Next time you log in this will be done
automatically.

To configure your current shell, run:
source $HOME/.cargo/env
pi@raspberrypi:~ $ cargo
error: command failed: 'cargo'
error: caused by: No such file or directory (os error 2)

nano /home/pi/.profile

if [ -n "$BASH_VERSION" ]; then
        # include .bashrc if it exists
        if [ -f "$HOME/.bashrc" ]; then
            . "$HOME/.bashrc"
        fi
    fi
    


# set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
        PATH="$HOME/bin:$PATH"
    fi
    
    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/.local/bin" ] ; then
        PATH="$HOME/.local/bin:$PATH"
    fi
    source "$HOME/.cargo/env"

also in /home/pi/.bashrc:

 source "$HOME/.cargo/env"

uname -a

Linux raspberrypi 5.10.17-v8+ #1403 SMP PREEMPT Mon Feb 22 11:37:54 GMT 2021 aarch64 GNU/Linux
1

There are 1 best solutions below

2
On

When asked for installation options select 2) for Custom Installation and then for "Default host triple?" enter "arm-unknown-linux-gnueabihf"

It has something to do with 32bit / 64 bit.