Hung up on editing the .bash_profile while running rbenv init on mac.
$ rbenv init
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
but get the message:
-bash: /Users/macbookpro/.bash_profile: Permission denied
I try to edit the .bash_profile directly but get the message:
I found this command to see the users:
$ ls -la ~ | grep bash
It shows:
-rw------- 1 macbookpro .bash_history
-rw-r--r-- 1 root .bash_profile
If I open the file using command:
$ sudo nano ~/.bash_profile
I guess I need to add this to .bash_profile:
$ export PATH="$HOME/.rbenv/bin:$PATH"
Or is it just the inner "part" of this?
Also how do I save this or do we have any easier solution (pretending my name is Fname-Lname)?
You'll need to use sudo in order to edit/append ~/.bash_profile on macOS.
sudo echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
Or just as you had done at the end of your question.
I was having the same issue what i did was i gave .bash_profile writable permission.
cd ~
sudo chmod 0777 .bash_profile
nano .bash_profile
After adding your modifcations you can now save the file with ^O and enter (return) after that you use ^x to exit.
Note: ^ is the control button
Related
I am facing some issues while installing go lang, have used below approach to install it.
sudo apt update
$ sudo curl -O https://storage.googleapis.com/golang/go1.10.1.linux-amd64.tar.gz
$ sudo tar -xvf go1.10.1.linux-amd64.tar.gz
$ sudo mv go /usr/local
everything went fine till the above step.
But when I am giving below command, I am getting a message
$ echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
Message: bash: export: '/usr/local/go/bin': not a valid identifier
$ source ~/.profile
Try this script:
git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh
Full details: https://github.com/udhos/update-golang
I am trying to update my /etc/shells file to include the path to a homebrew installed version of bash which resides at /usr/local/bin/bash
$ sudo echo /usr/local/bin/bash >> /etc/shells returns Permission denied and attempting to manually update is not allowed as it appears to be read-only.
Upon inspecting the file, the permissions are set as follows:
-rw-r--r-- 1 root wheel 179 Feb 21 2017 /etc/shells
So, with this in mind, and after looking at this article about Updating you shell with Homebrew I tried to initiate a shell as the root user and then try command above, i.e:
$ sudo -s
$ echo /usr/local/bin/bash >> /etc/shells
$ chsh -s /usr/local/bin/bash
However, this seems to hang on the first command ($ sudo -s). This spawns a bash process that eats up ~ 70% CPU and nothing happens.
Is there an alternative way one can update the /etc/shells/ file?
An approach to adding to a root-only file is echo /usr/local/bin/bash | sudo tee -a /etc/shells.
– Petesh
Would you be able to explain why that works and the sudo echo /usr/local/bin/bash >> /etc/shells does not though.
The latter doesn't work because the output redirection >> is (tried to be) applied by the shell before the sudo … is executed, and of course the user shell has no permission to do that.
Or you can just use this (I had to do this on macOS Mojave):
sudo sh -c "echo $(which zsh) >> /etc/shells"
chsh -s $(which zsh)
given this ~/.test file on Ubuntu 12.04:
alias ll='ls -la'
echo "TEST"
when I source ~/.test I get TEST printed to the terminal but the alias is not working.
Further information in response to questions:
This is a terminal copy/paste for illustration:
kontrol#smartxffts:~$ cat .test
alias ll='ls -la'
echo "TEST"
kontrol#smartxffts:~$ source .test
TEST
kontrol#smartxffts:~$ ll
ll: command not found
kontrol#smartxffts:~$ alias ll='ls -la'
kontrol#smartxffts:~$ ll
ll: command not found
The alias command works as expected with other accounts on the same system. This user where it doesn't work was created as follows:
sudo mkdir /home/kontrol
sudo useradd -u 1001 -b /home -s /bin/bash -G adm,cdrom,sudo,dip,plugdev,lpadmin,sambashare kontrol
sudo chown kontrol:kontrol kontrol/
Still stumped...!
There was a ll alias in the .bashrc with the option --color=auto. Removing that solved this. That still doesn't explain why a) the new alias of ll didn't overwrite the old one, and b) why the option --color=auto made it not work. Other ls aliases use that option and they work.
This question already has answers here:
Bash Deployment Script Permission Problem
(2 answers)
Closed 8 years ago.
I came across this weird problem just now and I can't seem to get to the bottom of it. I'm trying to add a config file to /etc/sudoers.d/ but get permission denied. In the example below, the file "tweedle" doesn't exist and:
drwxr-xr-x 2 root root 4.0K Jan 2 18:27 sudoers.d/
So here's the command:
$ sudo echo "tweedle ALL=(ALL) ALL" > /etc/sudoers.d/tweedle
-bash: /etc/sudoers.d/tweedle: Permission denied
It doesn't even work when I break it into two commands:
$ sudo touch /etc/sudoers.d/tweedle
$ sudo echo "poodle" > /etc/sudoers.d/tweedle
When I tested it locally, same problem:
$ cd ~
$ mkdir -m 755 tweedle
$ sudo chown root:root tweedle
$ sudo echo "battle" > ~/tweedle/beetle
-bash: /home/spanky/tweedle/beetle: Permission denied
$ sudo touch tweedle/beetle
$ sudo echo "battle" > tweedle/beetle
-bash: tweedle/beetle: Permission denied
Without sudo, all is well:
$ cd ~
$ mkdir poodle
$ echo "noodle" > poodle/bottle
$ cat poodle/bottle
noodle
Thoughts?
The echo command is being run as root, but the redirection is done by your shell, so it's executed as the current user, not as root.
The simplest solution is to invoke a root shell to run both the command and the redirection.
Rather than:
sudo echo line > file
try this:
sudo sh -c 'echo line > file'
or
sudo bash -c 'echo line > file'
The answer is to use "tee" with a pipe, a command I wasn't familiar with, so you can use sudo for the second half:
$ echo "tweedle ALL=(ALL) ALL" | sudo tee /etc/sudoers.d/tweedle
I can do this:
sudo nano .bash_profile
But when I do this:
sudo echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
I get this error message:
-bash: /Users/mycomputer/.bash_profile: Permission denied
When I do ls -al:
-rw-r--r-- 1 root staff 27 10 Aug 12:22 .bash_profile
Quick fix: do "sudo bash", to actually assume root privileges, THEN do the echo. It will work. sudo echo still uses your real uid, so it fails.