Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing rustup for all linux users #1085

Closed
Boscop opened this issue Apr 23, 2017 · 7 comments
Closed

Installing rustup for all linux users #1085

Boscop opened this issue Apr 23, 2017 · 7 comments

Comments

@Boscop
Copy link

Boscop commented Apr 23, 2017

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..

@nodakai
Copy link
Contributor

nodakai commented Apr 24, 2017

If you literally meant installing a system-wide rustup.rs for all users to install/update their own Rust toolchains and standard libraries

  1. You'll have tons of problems even if that is possible
  2. 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/.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/rustup

and 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

  • /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 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 )

@Boscop
Copy link
Author

Boscop commented Apr 25, 2017

Thanks a lot!
But yeah, installing rustup for all unix users should be easier, I think..

@Boscop
Copy link
Author

Boscop commented May 1, 2017

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?

@Boscop
Copy link
Author

Boscop commented May 1, 2017

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)

@Diggsey
Copy link
Contributor

Diggsey commented May 4, 2017

Dupe of #313

@Johnson9009
Copy link

@Boscop Try the method described in #2383.

@jrandolf
Copy link

In case anyone is looking for a macOS solution, the following script installs rustup as a system-wide toolchain manager:
https://gist.github.com/jun-sheaf/fc76a995307445161ef313280e18a39b

legoktm added a commit to freedomofpress/securedrop that referenced this issue May 31, 2023
Install Rust and rustup in slightly more straightforward directories and
unconditionally add it to $PATH instead of weirdly in /root/.cargo.

This setup is partially based on <rust-lang/rustup#1085 (comment)>,
which is described as unsupported for multiple users but our containers
are single-user.

The plan is to copy this to the development container as well.
legoktm added a commit to freedomofpress/securedrop that referenced this issue Jun 6, 2023
Install Rust and rustup in slightly more straightforward directories and
unconditionally add it to $PATH instead of weirdly in /root/.cargo.

This setup is partially based on <rust-lang/rustup#1085 (comment)>,
which is described as unsupported for multiple users but our containers
are single-user.

The plan is to copy this to the development container as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants