简体   繁体   English

我们如何为同一台 linux 机器上的所有用户安装 rustc、cargo?

[英]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.我有一台带有多个用户的 ubuntu 机器,其中一些用户有也没有 root 权限。 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.作为 root 用户,我想以 root 身份安装一次 rust(rustc, cargo) 并使其可供所有其他用户使用。 Present recommended way of installing rust is by using curl curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh目前推荐的安装 rust 的方法是使用 curl curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh . 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.我知道使用sudo可以让我在全局范围内安装一个程序,但是已经看到不鼓励使用 sudo 进行 rust 安装的线程。 How do we install rustc, cargo for all the users in the same linux machine?我们如何为同一台 linux 机器上的所有用户安装 rustc、cargo?

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.我只希望一个 root 用户能够更新 rustup 和 cargo,而所有其他用户都必须使用这个副本。

This github issue says concurrent usage of rustup is unsafe and can corrupt its working area.这个github issue说同时使用 rustup 是不安全的,并且会破坏它的工作区域。 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.如果使用全局 rust 工具链的目的是为了保持版本一致,你可以创建一个rustup-for-managing-rust-versions中指定的rust-toolchain文件,但如果是为了节省磁盘空间,恐怕没有官方文件说这样做是安全的。

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 .以只能由授权管理员更新的方式在系统范围内安装 Rust 的官方方法是使用官方独立安装程序 To install rust this way, you download the installer, extract it in a directory, and then run sudo ./install .要以这种方式安装 rust,请下载安装程序,将其解压缩到一个目录中,然后运行sudo ./install

Updating is equally as simple and is handled automatically if you installed the previous version of rust this way.如果您以这种方式安装了以前版本的 rust,更新同样简单,并且会自动处理。 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.如果您已经使用rustupapt等其他方法安装了 Rust,您可能应该在使用官方安装程序之前使用该方法卸载 rust。

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.使用上述方法安装 Rust toolchin。

  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.${RUST_VERSION}${TARGET}替换为各自的值。 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 .例如,如果您安装了1.60.0并希望安装附加目标wasm32-unknown-unknown ,您将下载rust- std- 1.60.0 - wasm32-unknown-unknown .tar.gz

  3. Extract, and run sudo ./install .提取并运行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.请记住,这些目标将在您安装下一版 Rust 时自动卸载,因此请准备好在每次更新 Rust 时重新安装您使用的任何其他目标。

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}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM