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 -s in a root shell, it installs to /root/.cargo.
When I move the .cargo folder to /usr/local/share, the cargo build cache won't be writable by non-root users..
rustup.rs for all users to install/update their own Rust toolchains and standard librariescurl https://sh.rustup.rs -sSf | shSo I'd assume another scenario:
Actually moving ~root/.cargo to /usr/local/share won't help you; I suggest you to remove all of
/usr/local/share/cargo~root/multirust (symlink to ~root/.rustup)~root/rustupand make a fresh start.
There are two environment variables to control rustup's behavior: RUSTUP_HOME and CARGO_HOME. The former controls where to install/find the actual Rust toolchains and the latter where to install the rustup wrapper (in disguise of rustc etc.) 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-path
You'll get files such as
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 use ln(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 )
Thanks a lot!
But yeah, installing rustup for all unix users should be easier, I think..
It'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
@Boscop Try the method described in #2383.
Most helpful comment
If you literally meant installing a system-wide
rustup.rsfor all users to install/update their own Rust toolchains and standard librariescurl https://sh.rustup.rs -sSf | shSo 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/rustupand 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:You'll get files such as
Then, install this shell script as
/usr/local/bin/rustcand 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 )