'How do we install rustc, cargo for all the users in the same linux machine?

I have a ubuntu machine with multiple users some of whom have and have not root privileges. Above that I have a limited storage for the same machine. I really don't want to install the same software multiple times by different users. As a root user I want to install rust(rustc, cargo) once as root and made it available for all other users. Present recommended way of installing rust is by using curl curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh. I know using sudo will let me install a program globally but have seen thread which discourage using sudo for rust installation. How do we install rustc, cargo for all the users in the same linux machine?

EDIT:

I only want one root user to have the power of updating rustup and cargo and all other users has to use this copy.



Solution 1:[1]

This github issue says concurrent usage of rustup is unsafe and can corrupt its working area. If the intention of using a global rust toolchain is to maintain a consistent version, you can create a rust-toolchain file as specified in rustup-for-managing-rust-versions, but if it is to save disk space, I'm afraid there is no official documentation which says it is safe to do it.

Solution 2:[2]

Here is how I got it to work using the offline installer:

export RUST_VERSION=1.60.0 && \
    export TMP_RUST_DIR=/tmp/rust && \
    mkdir -p "${TMP_RUST_DIR}" && \
    cd "${TMP_RUST_DIR}" && \
    curl -sLf "https://static.rust-lang.org/dist/rust-${RUST_VERSION}-x86_64-unknown-linux-gnu.tar.gz" |  \
      tar xvzf - -C "${TMP_RUST_DIR}" --strip-components=1 --exclude=rust-docs && \
    ./install.sh --without=rust-docs && \
    cd /tmp && rm -rf "${TMP_RUST_DIR}"

Solution 3:[3]

The official way to install Rust system-wide in a manner that is only updatable by an authorized administrator is to use the official standalone installer. To install rust this way, you download the installer, extract it in a directory, and then run sudo ./install.

Updating is equally as simple and is handled automatically if you installed the previous version of rust this way. If you have already installed Rust using another method like rustup or apt, you should probably use that method to uninstall rust prior to using the official installer.

You can also install additional targets system-wide using mini installers that provides target-specific files. The process for installing additional targets is similar to how you install the primary toolchain:

  1. Install Rust toolchin using the method described above.

  2. Download the target installer from:

    https://static.rust-lang.org/dist/rust-std-${RUST_VERSION}-${TARGET_TRIPLE}.tar.gz
    

    Replace ${RUST_VERSION} and ${TARGET} with their respective values. For example, If you installed 1.60.0 and want to install the the additional target wasm32-unknown-unknown, you'd download rust-std-1.60.0-wasm32-unknown-unknown.tar.gz.

  3. Extract, and run sudo ./install.

Keep in mind that that these targets will be automatically uninstalled when you install the next version of Rust, so be prepared to reinstall any additional target you use every time you update Rust.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nohup
Solution 2 leodotcloud
Solution 3