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

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.)

Related

check if a program is already installed [duplicate]

This question already has answers here:
How can I check if a program exists from a Bash script?
(39 answers)
Closed 2 years ago.
I want to check whether a program like firefox exists on ubuntu or not. In case it is not installed, I want to install it. I studied this topic and got information about command -v p programName, but I didn't understand how can I check if the program is installed or not. I want to write this:
#If firefox not installed:
sudo apt-get update
sudo apt install firefox
but I don't know how to write the if condition part.
#!/usr/bin/env sh
if ! command -v firefox >/dev/null 2>&1
then
sudo apt-get update
sudo apt install firefox
fi
Also notice that not all Linux systems use apt-get and that if sudo is
configured to request a password the script will stall and wait for
user to type a password which might be confusing.

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.

skip installing confirm('yes' or 'no') in Dockerfile [duplicate]

How do I install the anaconda / miniconda without prompts on Linux command line?
Is there a way to pass -y kind of option to agree to the T&Cs, suggested installation location etc. by default?
can be achieved by bash miniconda.sh -b (thanks #darthbith)
The command line usage for this can only be seen with -h flag but not --help, so I missed it.
To install the anaconda to another place, use the -p option:
bash anaconda.sh -b -p /some/path
AFAIK pyenv let you install anaconda/miniconda
(after successful instalation)
pyenv install --list
pyenv install miniconda3-4.3.30
For a quick installation of miniconda silently I use a wrapper
script script that can be executed from the terminal without
even downloading the script. It takes the installation destination path
as an argument (in this case ~/miniconda) and does some validation too.
curl -s https://gist.githubusercontent.com/mherkazandjian/cce01cf3e15c0b41c1c4321245a99096/raw/03c86dae9a212446cf5b095643854f029b39c921/miniconda_installer.sh | bash -s -- ~/miniconda
Silent installation can be done like this, but it doesn't update the PATH variable so you can't run it after the installation with a short command like conda:
cd /tmp/
curl -LO https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh -b -u
Here -b means batch/silent mode, and -u means update the existing installation of Miniconda at that path, rather than failing.
You need to run additional commands to initialize PATH and other shell init scripts, e.g. for Bash:
source ~/miniconda3/bin/activate
conda init bash

How to run (./) a bash script located in the cloud?

Using a ubuntu 16.04 what I do is :
Download the .sh script using wget https://gist.githubusercontent.com/...
Turn the .sh file executable sudo chmod guo+x sysInit.sh
Execute the code through sudo ./sysInit.sh
I was wondering if it is possible to run the code directly from the web.
Would be something like: sudo ./ https://gist.githubusercontent.com/....
Is it possible to do that?
You can use cUrl to download and run your script. I don't think its installed by default on Ubuntu so you'll have to sudo apt-get install curl first if you want to use it. To download and run your script with sudo just run
curl -sL https://gist.githubusercontent.com/blah.sh | sudo sh
Be warned this is very risky and not advised for security reasons. See this related question why-using-curl-sudo-sh-is-not-advised
Yes, it is possible using curl and piping the result to sh.
Try the following command.
curl https://url-to-your-script-file/scriptFile.sh | sh
No, sudo only works from a command line prompt in a shell

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

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.

Resources