DEV Community

nabbisen
nabbisen

Posted on • Updated on • Originally published at scqr.net

Fix rustup failed with "error: linker `cc` not found" (Rust 1.50 on Alpine Linux 3.13)

Summary

Today, I made a Dockerfile for Rust development on Alpine Linux.
I met the error below when installing Rust with Rustup:

# apk add rustup
Enter fullscreen mode Exit fullscreen mode

Then

# rustup-init -y
Enter fullscreen mode Exit fullscreen mode

The output was:

(...)
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)
...
error: build failed
The command '/bin/sh -c cargo build' returned a non-zero code: 101
Enter fullscreen mode Exit fullscreen mode

Environment

  • Alpine Linux 3.13
  • Rust 1.50
  • Rustup 1.23

Solution

It was fixed by adding build-base package:

# apk add rustup
# #apk add gcc       # here or
# apk add build-base # here
Enter fullscreen mode Exit fullscreen mode

Then

# rustup-init -y
Enter fullscreen mode Exit fullscreen mode

The output was:

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-musl
info: syncing channel updates for 'stable-x86_64-unknown-linux-musl'
info: latest update on 2021-02-11, rust version 1.50.0 (cb75ad5db 2021-02-10)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-linux-musl'

  stable-x86_64-unknown-linux-musl installed - rustc 1.50.0 (cb75ad5db 2021-02-10)


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
Enter fullscreen mode Exit fullscreen mode

As to Dockerfile, adding

ENV PATH=#{user-home-abs-path}/.cargo/bin:"$PATH"
Enter fullscreen mode Exit fullscreen mode

after the installation might bring a little more happiness :)

Conclusion

The minimal installation requires, of course, just gcc instead of build-base.

It is, however, not recommended because either musl-dev or libc-dev will be necessary in addition soon after.

In my case, installing Rust only was successful with gcc, but Actix Web, a Rust web framework using actors communication, required build-base.

Top comments (0)