Skip to content

Add Document of "How to Install Rust Environment for Multiple Users on Linux?" #2383

Description

@Johnson9009

Describe the problem you are trying to solve

For research and development team of lots of companies, they need a consistent Rust development environment for all of their team members, and generally the IT department or one team member help to install and maintain the development tools, so they want know how to install Rust development environment for all of their team members.

Their detailed goals and requirements can be listed below:

  • The Rust development environment only can be changed by specified team member or IT department.
  • All of team members can use "cargo", "rustc" and so on tools to develop Rust projects.

Even through issues #1085 and #313 is relevant to this problem, but none of them are exactly focus on this problem and none of them give out the solution of this problem, so I create this new issue and give out my solution.

Describe the solution you'd like

I'd like there is a document to tell the peoples who have the same requirement the current available solution.

The current available solution

This solution is inspired by nodakai's answer of issue #1085 (comment), thanks.

All of operations of this solution only need to be done by one team member or IT department, and then all of other team members can start Rust development work without doing anything.

Install Rust Environment

  1. Installation
    Here we assume you want install rustup into directory /nfs/rust/rustup and cargo into directory /nfs/rust/cargo.

    $ curl https://sh.rustup.rs -sSf | sudo env RUSTUP_HOME=/nfs/rust/rustup CARGO_HOME=/nfs/rust/cargo sh -s -- --default-toolchain stable --profile default --no-modify-path -y
  2. Configuration
    On Linux lots of environment setting is done by shell rc file, generally team will maintain a common shell rc file to do some settings that commonly used by all of the team members, and the new team member only need source the common shell rc file in his/her shell rc file then he/she can work.

    Here we assume your team has such common shell rc file, if not then you need tell all of your team members to do this step by themselves.

    Add below content into the common shell rc file.

    export RUSTUP_HOME=/nfs/rust/rustup
    export PATH=${PATH}:/nfs/rust/cargo/bin

Now all of the team members already can do Rust development work, the key of here is not explicitly set CARGO_HOME, so each team member will implicitly use ~/.cargo as his/her CARGO_HOME, that means when he/she use cargo run the cache and crates will store under his/her home directory.

Maintain Rust Environment

For example, the maintainer can use below command to install nightly toolchain and use it as default toolchain.

$ sudo env PATH=${PATH} RUSTUP_HOME=/nfs/rust/rustup CARGO_HOME=/nfs/rust/cargo rustup update nightly
$ sudo env PATH=${PATH} RUSTUP_HOME=/nfs/rust/rustup CARGO_HOME=/nfs/rust/cargo rustup default nightly

The key of here is explicitly set CARGO_HOME to the installation directory /nfs/rust/cargo, so rustup can do the job correctly.

System-wide Cargo config

For some team, maybe sometime need do some system-wide configuration of cargo, e.g., replace crates.io with a faster mirror, we know this requirement can be implemented by setting config file of cargo, generally these kind of settings are useful for all projects and all members of a team, so we want these kind of settings be configured in system-wide config.

We all know that now cargo hasn't a system-wide config, below content is referenced from The Cargo Book, we can find the file "/.cargo/config" is the most similar one to system-wide config.

/projects/foo/bar/baz/.cargo/config
/projects/foo/bar/.cargo/config
/projects/foo/.cargo/config
/projects/.cargo/config
/.cargo/config
$CARGO_HOME/config which defaults to:

  • Windows: %USERPROFILE%.cargo\config
  • Unix: $HOME/.cargo/config

You can store the config file inside cargo installation directory /nfs/rust/cargo/ and make symbolic link /.cargo/config to it on each machine.

$ sudo mkdir /.cargo
$ sudo ln -s /nsf/rust/cargo/config /.cargo/config

Notes

Activity

  1. rbtcollins commented on Jul 15, 2020

    @rbtcollins
    Contributor

    I think you will find that both cargo and rustup are unsafe for this use case, and that actually large companies don't have the strict requirement you are saying they do have (I say this having worked in the office of the CTO of a 300000 person company and in a different business unit of a 50000 person company).

    Rustup is not safe for concurrent use (see #988) and when used concurrently will corrupt it's working area (see #2417). Cargo uses locks for safety, but these will not scale to large numbers of users, because they are not RW locks, they are mutexes.

    Fundamental redesigns are needed to enable your proposed use case in a direct fashion.

    I think a much better fashion of supporting it is to make installing the company agreed version very reliable and straight forward, so that every developer can have it easily, regardless of their operating system, and if they need to build a custom compiler to test a bug fix - they can do that, and if they need to test nightly to test a bugfix - they can do that.

    If your company has a policy that says you must have a specific locked down version and developers cannot change their tooling at all - well, I have two recommendations for you:

    1. use system packages to manage this: snap, apt, rpm, etc - these are designed for this use case
    2. be prepared for your developers to be unable to do their jobs, as their use cases will not be fully met

    I'm going to close this bug, because we cannot add such a document, because it is not possible today, if ever. We can revisit this if in future rustup is robust against the stresses such an environment would bring.

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

  3. dclong commented on Jan 25, 2023

    @dclong

    Here's a blog post on installing Rust globally on linux.

    https://www.legendu.net/en/blog/install-rust-globally/

  4. jrandolf-old commented on Jan 25, 2023

    @jrandolf-old

    Here's a blog post on installing Rust globally on linux.

    https://www.legendu.net/en/blog/install-rust-globally/

    Setting CARGO_HOME to /usr/local/* is a very bad idea. The goal of installing anything global is to share resources among users of a system, however Cargo uses Cargo home for many things such as caching and what not. This would lead to file locks if several users were compiling. You should take a look at the macOS script and adapt it to Linux. I could also post my Linux one if desired.

  5. madjxatw commented on Feb 1, 2023

    @madjxatw

    @jun-sheaf , I'm new to rust, please post one for ref, thanks.

  6. savire commented on Jul 12, 2024

    @savire

    So basically rust will surely crash if there are a lot of users compiling stuff using shared libraries system wide?
    I personally think peoples will still have such a use case though even though they are not "Big Companies".
    If only it could share libraries like what Node did easily because normally those compiled libs will be left as is once its compiled so there should not be chances of it being re-compiled again unless something changes.

  7. blackliner commented on Jun 21, 2025

    @blackliner

    In my case, I have self hosted GitHub action runners, installed by multi runner (github project). Each runner gets it's dedicated user, and right now I need to install rustup for each user.

    I would wish that rustup (the binary) could be installed once, caches for the toolchains are shared with mutexes (doesn't happen that often), and each user has their own cargo home.

  8. rami3l commented on Jun 21, 2025

    @rami3l
    Member

    @blackliner We will be supporting this use case in the future, probably with per toolchain locking: #3937

    Please bear with me while I'm still finding my way out of this. 🙏

  9. blackliner commented on Jun 21, 2025

    @blackliner

    No worries, I found out in the meantime Ubuntu 24.04 supports apt install rustup, which will provide a good compromise:

    • central rustup binary
    • each user gets their own installation of rust, so no concurrency issues
    • small downside: the download cache is not reused for the toolchain installs, but I'll still take it

    Now what to do for Ubuntu 22.04 😬 EDIT: maybe the cleanest solution for now is to run the curl | sh for each user...

  10. fiveseven-lambda commented on Jul 14, 2025

    @fiveseven-lambda

    FWIW, the rustup package in Arch Linux works the same way. A system-wide binary with per-user toolchain installations.

  11. joeskeen commented on Jul 20, 2025

    @joeskeen

    Just thought I'd throw in my own use case for a system-wide installation.

    My computer is only used by me, but I store my user directory on my NAS so I can access all my files easily if I log into other computers in my home lab. Having ALL the rust installation inside of my HOME directory means that when I'm installing/upgrading Rust, it's doing a TON of network I/O. I'd rather install and use it on one machine, and spare the hassle of streaming all the rust stuff over the network whenever I need to use it.

    (It's possible there is a better solution for what I'm trying to accomplish, but that's where I am today 😉)

  12. rami3l commented on Jul 20, 2025

    @rami3l
    Member

    Just thought I'd throw in my own use case for a system-wide installation.

    My computer is only used by me, but I store my user directory on my NAS so I can access all my files easily if I log into other computers in my home lab. Having ALL the rust installation inside of my HOME directory means that when I'm installing/upgrading Rust, it's doing a TON of network I/O. I'd rather install and use it on one machine, and spare the hassle of streaming all the rust stuff over the network whenever I need to use it.

    (It's possible there is a better solution for what I'm trying to accomplish, but that's where I am today 😉)

    @joeskeen Thanks for sharing! However, what you would like to achieve may be done more efficiently by overriding RUSTUP_HOME to somewhere actually on your machine prior to installation?

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions