Skip to content

Installing rustup for all linux users #1085

Description

@Boscop

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

Activity

  1. nodakai commented on Apr 24, 2017

    @nodakai
    Contributor

    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 )

  2. Boscop commented on Apr 25, 2017

    @Boscop
    Author

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

  3. Boscop commented on May 1, 2017

    @Boscop
    Author

    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?

  4. Boscop commented on May 1, 2017

    @Boscop
    Author

    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)
    
  5. Diggsey commented on May 4, 2017

    @Diggsey
    Contributor

    Dupe of #313

  6. Johnson9009 commented on Jun 20, 2020

    @Johnson9009

    @Boscop Try the method described in #2383.

  7. jrandolf-old commented on Jan 25, 2023

    @jrandolf-old

    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

  8. fbuccioni commented on Apr 14, 2026

    @fbuccioni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions