Repository navigation
Installing rustup for all linux users #1085
Description
Activity
If you literally meant installing a system-wide
rustup.rsfor all users to install/update their own Rust toolchains and standard libraries- You'll have tons of problems even if that is possible
- It doesn't make much sense, as you can easily ask each user to run
curl https://sh.rustup.rs -sSf | sh
So I'd assume another scenario:
If you meant installing system-wide Rust toolchains and standard libraries for all users
Actually moving
~root/.cargoto/usr/local/sharewon't help you; I suggest you to remove all of/usr/local/share/cargo~root/multirust(symlink to~root/.rustup)~root/rustup
and make a fresh start.
There are two environment variables to control
rustup's behavior:RUSTUP_HOMEandCARGO_HOME. The former controls where to install/find the actual Rust toolchains and the latter where to install therustupwrapper (in disguise ofrustcetc.) After a successful installation, you'll want to configure them for ordinary users' convenience.So I'd recommend you to install everything under
/usr/local/share/rust(maybe/opt/rust?) and write a simple Bash wrapper to configure the environment variables.First, run these command as
root:$ RUSTUP_HOME=/opt/rust $ export RUSTUP_HOME $ CARGO_HOME=/opt/rust $ export CARGO_HOME $ curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-pathYou'll get files such as
- /opt/rust/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc
- /opt/rust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-13f36e2630c2d79b.rlib
- /opt/rust/bin/rustc
- /opt/rust/bin/rustup
Then, install this shell script as
/usr/local/bin/rustc#!/bin/sh RUSTUP_HOME=/opt/rust exec /opt/rust/bin/${0##*/} "$@"
and repeat that for all the commands under
/opt/rust/bin/(you can useln(1)for your convenience.)Then ordinary users will be able to use any of standard Rust commands except they cannot install/update Rust toolchains and standard libraries. In particular Cargo downloads will be stored in each user's
~/.cargo.
@brson There seems to be a genuine need for a usage like this, I guess it's worth covering in the official doc (though the requirement on which component to "share" seems to vary case to case: cf. #313 )
Reacted by Łukasz Kółko, matt_, AMIY !, Antoine Chauvin, Matthew J Blackwood, Bastien Abadie, ET, Michael Steinbaugh, kuator, deprecated and 32 moreReacted by acgxv, Kashiwara, Ayush, Alessandro Pezzè, Han Boetes, Jason Michael Baumgartner, Jeff Hiner, Andrés Castro Socolich, Lily, IronSpecs and 5 moreReacted by Oliver ArendReacted by Nate Bennett, Arthur, Sam, Adrian and JakubReacted by Ricardo Fernández SerrataThanks a lot!
But yeah, installing rustup for all unix users should be easier, I think..Reacted by Timothy Hobbs, Jason Michael Baumgartner, Erland Lewin, Paul, Alex Pavlovich, Mason Ginter, Travis Gockel, YiraSan, Oliver Arend, Nate Bennett and 12 moreIt's weird, when I tried to add a rustup target as user1 (without sudo) it succeeded even though it shouldn't.
But also, when I switch to another user, it can't find rustup (or any of the other rust executables):
[user1@localhost ~]$ rustup target add i686-unknown-linux-gnu info: downloading component 'rust-std' for 'i686-unknown-linux-gnu' 69.5 MiB / 69.5 MiB (100 %) 10.4 MiB/s ETA: 0 s info: installing component 'rust-std' for 'i686-unknown-linux-gnu' [user1@localhost ~]$ rustup show Default host: x86_64-unknown-linux-gnu installed targets for active toolchain -------------------------------------- i686-unknown-linux-gnu x86_64-unknown-linux-gnu active toolchain ---------------- nightly-x86_64-unknown-linux-gnu (default) rustc 1.19.0-nightly (06fb4d256 2017-04-30) [user1@localhost ~]$ whereis rustup rustup: /usr/local/bin/rustup /opt/rust/bin/rustup [user1@localhost ~]$ sudo -i -u user2 [user2@localhost ~]$ whereis rustup rustup: /usr/local/bin/rustup /opt/rust/bin/rustup [user2@localhost ~]$ rustup show bash: rustup: command not found...Why?
And I can't even build:
[user1@localhost ~]$ mkdir foo [user1@localhost ~]$ cd foo/ [user1@localhost foo]$ cargo init --bin Created binary (application) project [user1@localhost foo]$ cargo run error: An unknown error occurred To learn more, run the command again with --verbose. [user1@localhost foo]$ cargo run --verbose error: could not execute process `rustc -vV` (never executed) Caused by: Permission denied (os error 13)Dupe of #313
- added a commit that references this issue
on Feb 28, 2022 In case anyone is looking for a macOS solution, the following script installs
rustupas a system-wide toolchain manager:
https://gist.github.com/jun-sheaf/fc76a995307445161ef313280e18a39b- added 2 commits that reference this issue
on May 31, 2023 I have done this script to globally install rust
https://gist.github.com/fbuccioni/95f1b92cef35ca45f8bbbc9d86fc2ea8
What's the recommended way to install rustup for all users on a linux machine?
When I run
curl https://sh.rustup.rs -sSf | sh -sin a root shell, it installs to/root/.cargo.When I move the
.cargofolder to/usr/local/share, the cargo build cache won't be writable by non-root users..