Could not write to .bash_profile when installing Rust on macOS Sierra - macos

I am trying to install Rust by running the following:
sudo curl https://sh.rustup.rs -sSf | sh
I keep getting this following error:
could not write rcfile file: '/Users/pro/.bash_profile'
info: caused by: Permission denied (os error 13

Give a try using this not using sudo:
curl https://sh.rustup.rs -sSf | sh -s -- --help
If that works then probably you could try:
curl https://sh.rustup.rs -sSf | sh -s -- --no-modify-path
If the command with the --no-modify-path option works, you'll have to manually update .bash_profile to include it in your path:
source ~/.cargo/env

The accepted answer worked for me in the working terminal session only, it did not work after restarting my MacBokk Air.
The solution worked with me is:
// 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
UPDATE
As shown here:
It sounds like the user running the install script didn't have
permission/wasn't owner of ~/.bash_profile, which is unusual. Maybe
yarn should check and be more helpful, but in any case it's probably a
good idea to run sudo chown whoami ~/.bash_profile
So, I tried the below command:
sudo chown h_ajsf ~/.bash_profile
And everything completed smoothly.

Related

Rust .sh installer require permission to write to .bashrc [duplicate]

This question already has answers here:
Could not write to .bash_profile when installing Rust on macOS Sierra
(2 answers)
Closed 1 year ago.
I was trying to install Rust on my Mac with the command
sudo curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
When I selected the default option that is supposed to edit .bashrc, I got the error
could not amend shell profile: '/Users/andreyshedko/.bashrc': could not write rcfile file: '/Users/andreyshedko/.bashrc': Permission denied (os error 13)
The command already has sudo permission, what else is missing?
sh wasn't not executed with sudo, only curl (unnecessarily so) was. You probably meant to use
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sudo sh
but executing unknown code with root privileges seems like a horrible idea. (It's also not obvious why a process run under your user id would fail to have permission to write to your own .bashrc file.)

source /.bash_profile command provide error

I run the command source ~/.bash_profile and get the following error:
$ source ~/.bash_profile
-sh: /Users/chaklader/.sdkman/contrib/completion/bash/sdk: line 37: syntax error near unexpected token `<'
-sh: /Users/chaklader/.sdkman/contrib/completion/bash/sdk: line 37: ` done < <(curl --silent "${SDKMAN_CANDIDATES_API}/candidates/all")'
The login shell that I use is bin/sh:
Whats the issue here and how to solve it?
This is how I solved the issue with the provided steps:
Install Homebrew from the docs on their homepage
Install Git using Homebrew (optional, but nice to have a more up-to-date git)
brew install git
Now install bash:
brew install bash
Add this install of bash to the allowed shells list:
echo '/usr/local/bin/bash' | sudo tee -a /etc/shells;
Homebrew installs things to /usr/local/Cellar/ by default, then symlinks any binaries to /usr/local/bin, so you've now got the latest bash sitting at /usr/local/bin/bash
Finally, change your shell to use this new one:
chsh -s /usr/local/bin/bash
Open a new terminal window/tab, and run these commands to double-check your work:
$ echo $SHELL
/usr/local/bin/bash
$ echo $BASH_VERSION
5.1.8(1)-release
This also solved the issue for running the source ~/.bash_profile whenever I open a new window in the terminal.
Reference:
The answer is from here How do I install Bash >= 3.2.25 on Mac OS X 10.5.8? by user jeffbyrnes

Errno 13 Permission denied when installing gcloud in macOS Mojave 10.14.2

When trying to install gcloud I am getting the following error [Errno 13] Permission denied.
I tried running the install with sudo, running the manual install and nothing.
The following errors where generated when running:
sudo curl https://sdk.cloud.google.com | bash
sudo curl "$url" | bash will invoke curl with sudo, but the bash, which is in another subshell, is not affected by the previous sudo.
It maybe not necessary to invoke curl with root, but bash seems need root. So just simply move sudo to where needs, for example curl "$url" | sudo bash.

command not found even when "which" shows its path with sudo

I'm on Fedora release 25 with zsh 5.2
I am trying to use a command with sudo. (In this example, docker-compose)
Problem:
which command shows where it is.
$ sudo PATH=$PATH which docker-compose
/usr/local/bin/docker-compose
In spite of that, command not found
$ sudo PATH=$PATH docker-compose
sudo: docker-compose: command not found
I could make it work by sudo `which docker-compose` but I want to know why this occurs.
What I tried:
I double-quoted PATH=$PATH but got the same result.
$ sudo "PATH=$PATH" docker-compose
sudo: docker-compose: command not found
/usr/local/bin/ is not on root path. Check with
sudo bash -c 'echo "$PATH"'
/usr/sbin:/usr/bin:/sbin:/bin
Use absolute path to the command.
Adding /usr/local/bin to root path seems to be a security risk.

Is there a way to fix this error in terminal: -bash: HOME/.rvm/scripts/rvm: No such file or directory?

I'm new to Ruby and just installed it following the instructions on this website.
I'm not sure why, but now whenever I open terminal, I get the following error message:
-bash: HOME/.rvm/scripts/rvm: No such file or directory
Is there something I'm missing? As far as I can tell, Ruby is installed correctly and is running fine.
It looks like you put HOME in your .bash_profile instead of $HOME. You should also verify that your .rvm directory exists in your home directory. You could also check the value of $HOME by running echo $HOME in a shell, and it should return something like /home/yourname.
Note: You could change "$HOME" to "~".
This maybe solve your problem:
Before you install RVM, you can input this in your terminal to check server key:
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
Then you can input the following command to install rvm
curl -L https://get.rvm.io | bash -s stable
Just have a try~
You must source the rvm scripts so that they are available to your terminal session
source /usr/local/rvm/scripts/rvm
source ~/.rvm/scripts/rvm
You may want to add it to your .bash_profile or .bashrc file so that they are executed every time you load a terminal window like so:
$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> .bashrc

Resources