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

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

Closed
Johnson9009 opened this issue Jun 20, 2020 · 5 comments

Comments

@Johnson9009
Copy link

Johnson9009 commented Jun 20, 2020

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

@rbtcollins
Copy link
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.

@jun-sheaf
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

@dclong
Copy link

dclong commented Jan 25, 2023

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

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

@jun-sheaf
Copy link

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.

@madjxatw
Copy link

madjxatw commented Feb 1, 2023

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

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

No branches or pull requests

5 participants