Can't install Rust on Ubuntu

I'm planning on using the ubuntu image "mcr.microsoft.com/devcontainers/base:ubuntu-22.04".

So I start a container

docker run --rm -it mcr.microsoft.com/devcontainers/base:ubuntu-22.04 bash

Now, I try everything from the official rust website (Install Rust - Rust Programming Language) and nothing works.

Any can show me what they did inside an Ubuntu container image to install Rust ?
I need an Ubuntu image, not a base Rust docker image.

Can you be more precise? The Installer is interactive. What options did you choose? Where does it fail and with what error message?

This is my output, everything works correctly.

Trying to pull mcr.microsoft.com/devcontainers/base:ubuntu-22.04...
Getting image source signatures
Copying blob 4a023cab5400 done   | 
Copying blob 8913270111b4 done   | 
Copying blob d1a1863e4d1f done   | 
Copying blob 3ff0e4788ecf done   | 
Copying blob 02bce8e816a7 done   | 
Copying blob 918331f3e198 done   | 
Copying blob fe7361841eb6 done   | 
Copying blob 6403833e37ce done   | 
Copying config c1decbdf21 done   | 
Writing manifest to image destination
root ➜ / $ 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:

  /root/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /root/.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:

  /root/.cargo/bin

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

  /root/.profile
  /root/.bashrc
  /root/.zshenv

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation
>

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2024-05-02, rust version 1.78.0 (9b00956e5 2024-04-29)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
 24.3 MiB /  24.3 MiB (100 %)  22.1 MiB/s in  1s ETA:  0s
info: downloading component 'rustc'
 63.7 MiB /  63.7 MiB (100 %)  20.8 MiB/s in  3s ETA:  0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 15.1 MiB /  15.1 MiB (100 %) 561.6 KiB/s in 55s ETA:  0s    
info: installing component 'rust-std'
 24.3 MiB /  24.3 MiB (100 %)   4.8 MiB/s in  7s ETA:  0s
  5 IO-ops /   5 IO-ops (100 %)   0 IOPS in  5s ETA: Unknown
info: installing component 'rustc'
 63.7 MiB /  63.7 MiB (100 %)   7.9 MiB/s in 32s ETA:  0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu installed - rustc 1.78.0 (9b00956e5 2024-04-29)


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, you need to source
the corresponding env file under $HOME/.cargo.

This is usually done by running one of the following (note the leading DOT):
. "$HOME/.cargo/env"            # For sh/bash/zsh/ash/dash/pdksh
source "$HOME/.cargo/env.fish"  # For fish
root ➜ / $ . .   
./  ../ 
root ➜ / $ . .
./  ../ 
root ➜ / $ . ~/.cargo/env
root ➜ / $ which rustc
/root/.cargo/bin/rustc
root ➜ / $ cargo new --bin hello
    Creating binary (application) `hello` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
root ➜ / $ cd hello/
root ➜ /hello (master) $ cargo run
   Compiling hello v0.1.0 (/hello)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.11s
     Running `target/debug/hello`
Hello, world!
1 Like

Once I'm inside the container sometimes I get

root ➜ / $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer
curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104
rustup: command failed: downloader https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init /tmp/tmp.C2bWgAeE4s/rustup-init x86_64-unknown-linux-gnu

The other type of result when I keep retrying several times is

root ➜ / $ 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:

  /root/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /root/.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:

  /root/.cargo/bin

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

  /root/.profile
  /root/.bashrc
  /root/.zshenv

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation
>

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2024-05-02, rust version 1.78.0 (9b00956e5 2024-04-29)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
 12.5 MiB /  15.1 MiB ( 83 %)   5.4 MiB/s in  2s ETA:  0s
error: component download failed for rust-docs-x86_64-unknown-linux-gnu: error decoding response body

To check if the problem comes from my connection, I tried ping and no problem for that part

 ping google.com
PING google.com (172.217.20.206) 56(84) bytes of data.
64 bytes from waw02s08-in-f206.1e100.net (172.217.20.206): icmp_seq=1 ttl=113 time=12.5 ms
64 bytes from waw02s08-in-f206.1e100.net (172.217.20.206): icmp_seq=2 ttl=113 time=15.8 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 12.491/14.120/15.750/1.629 ms

(repost of Installing Rust in a container is not deterministic)

Testing that in a dockerfile and in an interactive command isn't quite the same.
So, I made a separate post to talk about it.

Otherwise, the other post might become too clunky to understand.

You get the exact same error here. You have a wonky internet connection, or a strange proxy or VPN.

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.