简体   繁体   English

将rustc安装在其他用户的主目录中时,如何执行?

[英]How do you execute rustc when it is installed in another users's home directory?

I downloaded and installed the Rust compiler via: 我通过以下方式下载并安装了Rust编译器:

sudo curl https://sh.rustup.rs -sSf | sh

Although prefixed with sudo, it still installs to a local directory: $HOME/.cargo 尽管以sudo $HOME/.cargo ,它仍然安装到本地目录: $HOME/.cargo

From the account where it is installed, doing rustc --version gives 1.16.0 (...) . 从安装它的帐户,执行rustc --version给出1.16.0 (...)

I would like to execute rustc from a Linux account different than the one in which it was installed. 我想从与安装它不同的Linux帐户执行rustc。 Is this possible? 这可能吗?

I created a logical link to the .cargo directory and added $HOME/.cargo/bin to the front of my PATH. 我创建了到.cargo目录的逻辑链接,并将$HOME/.cargo/bin到PATH的前面。

But, rustc --version from this other account gives this puzzling message: 但是,其他帐户的rustc --version会给出以下令人困惑的消息:

error: no default toolchain configured

If you install via rustup (which is recommended) you have two important folders in your home directory: .cargo and .rustup (and depending on your version a soft link .multirust pointing to .rustup for backwards-compatibility reasons). 如果通过rustup安装(建议使用),则您的主目录中有两个重要文件夹: .cargo.rustup (根据您的版本,出于向后兼容的原因,软链接.multirust指向.rustup )。 So you also have to create a link to .rustup . 因此,您还必须创建一个指向.rustup的链接。 That's what the strange error message is all about. 这就是奇怪的错误消息的全部内容。

I would like to execute rustc from a Linux account different than the one in which it was installed. 我想从与安装它不同的Linux帐户执行rustc。 Is this possible? 这可能吗?

This, however, is a different question. 但是,这是一个不同的问题。 It's important to note that many commands, even just cargo build , will attempt to write in one of those directories (in case of cargo build to cache downloaded crates). 重要的是要注意,许多命令,甚至只是cargo build ,都将尝试写入那些目录之一(如果采用cargo build来缓存下载的板条箱)。 If the second user has full read/write/execute permissions inside both directories mentioned above, it should work -- but it's quite questionable if that's a good solution. 如果第二个用户在上面提到的两个目录中都具有完全的读/写/执行权限,则它应该可以工作-但是,这是否是一个很好的解决方案却值得怀疑。 If you want, you can move both folders anywhere you like, give both users full permissions to both and create soft-links per user. 如果需要,可以将两个文件夹都移动到任意位置,为两个用户授予完全的权限,并为每个用户创建软链接。


But again, depending on how much privacy is needed, it gets more complicated (but if, say, you have an account for your work and one account for your hobby stuff, this isn't that important). 但是同样,根据需要多少隐私,它会变得更加复杂(但是,例如,如果您有一个用于工作的帐户,一个帐户用于您的业余爱好,那么这并不重要)。 Here is an overview over both folders: 以下是这两个文件夹的概述:

  • ~/.cargo/<several files> : small, user specific, somewhat confidential files (may contain login data for crates.io) ~/.cargo/<several files> :较小的,特定于用户的,有些机密的文件(可能包含crates.io的登录数据)
  • ~/.cargo/bin : installed programs and proxies for programs (around 100MB), execute permission needed ~/.cargo/bin :已安装的程序和程序的代理(大约100MB),需要执行权限
  • ~/.cargo/registry : library cache, can get quite big, not confidential ~/.cargo/registry :库缓存,可以很大,不是机密的
  • ~/.rustup/toolchains : installed compiler versions and everything else you can install via rustup ~/.rustup/toolchains :已安装的编译器版本以及您可以通过rustup安装的所有其他版本
  • ~/.rustup/<tmp and update-hashes> : somewhat temporary files ~/.rustup/<tmp and update-hashes> :临时文件
  • ~/.rustup/settings.toml : small, user specific ~/.rustup/settings.toml :较小,用户特定

So depending in your needs you can have real .cargo and .rustup folders in your home directory and just soft link the folders like .cargo/bin and so on. 因此,根据您的需要,您可以在主目录中拥有真实的 .cargo.rustup文件夹,并只需软链接这些文件夹即可,例如.cargo/bin等。

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

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