Repository navigation
Add Document of "How to Install Rust Environment for Multiple Users on Linux?" #2383
Description
Activity
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:
- use system packages to manage this: snap, apt, rpm, etc - these are designed for this use case
- 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.
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/fc76a995307445161ef313280e18a39bHere's a blog post on installing Rust globally on linux.
Here's a blog post on installing Rust globally on linux.
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.
Reacted by Martin Habovštiak@jun-sheaf , I'm new to rust, please post one for ref, thanks.
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.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.
@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. 🙏
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 | shfor each user...FWIW, the
rustuppackage in Arch Linux works the same way. A system-wide binary with per-user toolchain installations.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 😉)
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_HOMEto somewhere actually on your machine prior to installation?
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:
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
Installation
Here we assume you want install
rustupinto directory/nfs/rust/rustupandcargointo 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 -yConfiguration
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
sourcethe 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.
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~/.cargoas his/herCARGO_HOME, that means when he/she usecargo runthe cache and crates will store under his/her home directory.Maintain Rust Environment
For example, the maintainer can use below command to install
nightlytoolchain and use it as default toolchain.The key of here is explicitly set
CARGO_HOMEto the installation directory/nfs/rust/cargo, sorustupcan do the job correctly.System-wide Cargo
configFor some team, maybe sometime need do some system-wide configuration of
cargo, e.g., replacecrates.iowith a faster mirror, we know this requirement can be implemented by settingconfigfile ofcargo, 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-wideconfig.We all know that now
cargohasn't a system-wideconfig, below content is referenced fromThe Cargo Book, we can find the file "/.cargo/config" is the most similar one to system-wideconfig.You can store the
configfile insidecargoinstallation directory/nfs/rust/cargo/and make symbolic link/.cargo/configto it on each machine.Notes