DEV Community

loading...

Rustup on Alpine Linux: Fix "error: linker `cc` not found"

Heddi Nabbisen
An ICT designer/developer and a security monk with "a cool brain and a warm heart". OpenBSD/Rust etc. Interested in social issues and relationships. Founder of Scqr Inc.
Updated on ・2 min read

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

# rustup-init -y
...
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

which was fixed by adding build-base package:

# apk add rustup
# #apk add gcc       # here or
# apk add build-base # here

# rustup-init -y
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.

Note

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.

Environment

  • Alpine Linux 3.13
  • Rust 1.50
  • Rustup 1.23

Discussion (0)

Forem Open with the Forem app