在macOS Sierra上安装Rust时无法写入.bash_profile

Sam*_*are 4 macos terminal rust

我正在尝试通过运行以下命令来安装Rust:

sudo curl https://sh.rustup.rs -sSf | sh
Run Code Online (Sandbox Code Playgroud)

我一直收到以下错误:

could not write rcfile file: '/Users/pro/.bash_profile'
info: caused by: Permission denied (os error 13
Run Code Online (Sandbox Code Playgroud)

nba*_*ari 12

尝试使用不使用sudo:

curl https://sh.rustup.rs -sSf | sh -s -- --help
Run Code Online (Sandbox Code Playgroud)

如果有效,那么你可能会尝试:

curl https://sh.rustup.rs -sSf | sh -s -- --no-modify-path 
Run Code Online (Sandbox Code Playgroud)

  • 谢谢了。必须将`source〜/ .cargo / env`添加到我的.bash_profile中 (2认同)

Has*_*sef 12

接受的答案仅在工作终端会话中对我有效,重新启动我的 MacBokk Air 后不起作用。

与我合作的解决方案是:

// Opened .bash_profile file, I used VS code as editor, this the `code` below
Hasans-Air:~ h_ajsf$ sudo code $HOME/.bash_profile
// Add the below to the .bash_profile file
PATH=$PATH:/Users/$USER/.cargo/bin
//Saved the file
//Updated env by:
Hasans-Air:~ h_ajsf$ source $HOME/.bash_profile
//Check for JAVA_HOME
Hasans-Air:~ h_ajsf$ rustup
Run Code Online (Sandbox Code Playgroud)

更新

如图所示:

听起来运行安装脚本的用户没有权限/不是 ~/.bash_profile 的所有者,这是不寻常的。也许纱线应该检查并且更有帮助,但无论如何,运行sudo chownwhoami可能是个好主意~/.bash_profile

所以,我尝试了以下命令:

sudo chown h_ajsf ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)

而一切都顺利完成。

在此输入图像描述

  • 这似乎是比已接受的答案更好的选择,因为 1) 它解决了潜在问题(文件权限),2) 解锁了 `rustup`,它还更新了 `.zshenv` 的环境变量...对于新的 Mac OS 用户很重要,其中 ZSH 是默认 shell `sudo chown $(whoami) ~/.bash_profile` 是替代方案 (2认同)