Homebrew install permissions issue - osx-snow-leopard

I have a standard homebrew install inside of usr/local/
When I try:
Larson-2:~ larson$ brew install postgresql
Error: Cannot write to /usr/local/Cellar
And when I use sudo:
Larson-2:~ larson$ sudo brew install postgresql
Cowardly refusing to `sudo brew install'
What am I doing wrong?

You somehow have limited permissions to /usr/local/Cellar. Brew doesn't like to install with sudo which is why it refuses.
Check the permissions:
ls -ld /usr/local/Cellar
Open them up for writing:
sudo chmod a+w /usr/local/Cellar

Do not use sudo when working with brew (for security reasons).
You've to simple set-up your permissions.
So I would go even further and change the permissions to:
sudo chgrp -R admin /usr/local /Library/Caches/Homebrew
sudo chmod -R g+w /usr/local /Library/Caches/Homebrew
and then apply the specific group (either admin or staff) to user which should be allowed to use brew command. Check groups of your user via: id -Gn).
If there are further issues, run: brew doctor to see what's wrong.

I'd change the group permissions:
$ chgrp -R admin /usr/local/Cellar
$ chmod g+w /usr/local/Cellar
assuming your user account is in group admin.

This also happens if you have multiple users on your machine. If so, it would be best for you to change the user since every other approach would have you messing around with a lot more files and folders than just /usr/local/Cellar
Use su userWhoInstalledBrew.

The problem can be solved by changing the directory's owner to the current user:
sudo chown -R $USER /usr/local
This answer is taken from: https://github.com/Homebrew/homebrew/issues/17884

Following the advice chukcha14 provided in his answer at There is no Cellar file in my usr/local dir for brew, I did this:
jaimes-mbp:SMR jaimemontoya$ brew install mongodb-community#4.2
Warning: You are using OS X 10.15.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
Error: Could not create /usr/local/Cellar
Check you have permission to write to /usr/local
jaimes-mbp:SMR jaimemontoya$ sudo mkdir /usr/local/Cellar
Password:
jaimes-mbp:SMR jaimemontoya$ sudo chown $(whoami) /usr/local/Cellar
jaimes-mbp:SMR jaimemontoya$ brew install mongodb-community#4.2
Warning: You are using OS X 10.15.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
==> Installing mongodb-community from mongodb/homebrew-brew
==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.2.3.tgz
###################################################################################### 100.0%
Error: Failed to install plist file
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink .
/usr/local/opt is not writable.
You can try again using:
brew link mongodb-community
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall mongodb/brew/mongodb-community`
==> Caveats
To have launchd start mongodb/brew/mongodb-community at login:
ln -sfv /usr/local/opt/mongodb-community/*.plist ~/Library/LaunchAgents
Then to load mongodb/brew/mongodb-community now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
Or, if you don't want/need launchctl, you can just run:
mongod --config /usr/local/etc/mongod.conf
==> Summary
🍺 /usr/local/Cellar/mongodb-community/4.2.3: 20 files, 304M, built in 110 seconds
jaimes-mbp:SMR jaimemontoya$ sudo mkdir /usr/local/opt
jaimes-mbp:SMR jaimemontoya$ sudo chown $(whoami) /usr/local/opt
jaimes-mbp:SMR jaimemontoya$ brew link mongodb-community
Linking /usr/local/Cellar/mongodb-community/4.2.3... 13 symlinks created
jaimes-mbp:SMR jaimemontoya$

funny but I received the Error: Cannot write to /usr/local/Cellar message due to lack of disk space .. :/ ( 18MB left )

Related

Zsh: Command Not found : mongo After trying to install mongodb 4.2 using brew

I have tried the following steps to install and setup mongodb in my mac from here https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/ but I got the following error when running the final "mongo" command in my terminal:
Error Message - Zsh: Command Not found : mongo
This error msg occurred after trying to install mongodb 4.2 using brew
sudo chown -R $(whoami) $(brew --prefix)/*
then
brew tap mongodb/brew
then
brew install mongodb-community#4.2
and
brew services start mongodb-community#4.2
or
mongod --config /usr/local/etc/mongod.conf
then
ps aux | grep -v grep | grep mongod
and
mongo
running brew services start mongodb-community#4.2 returns:
Successfully started `mongodb-community#4.2` (label: homebrew.mxcl.mongodb-community#4.2)
running ps aux | grep -v grep | grep mongod returns:
9081 0.2 0.5 5528024 41856 ?? S 3:01pm 0:01.48 /usr/local/opt/mongodb-community#4.2/bin/mongod --config /usr/local/etc/mongod.conf
7613 0.0 0.1 4298832 5600 s000 T 2:47pm 0:00.08 vim /usr/local/etc/mongod.conf
running mongod --config /usr/local/etc/mongod.conf returns:
zsh: command not found: mongod
There are also no mongo files in my /usr/local/bin directory after using these commands
I created a data/db folder in my /usr/local/bin directory using the following commands:
sudo mkdir -p /usr/local/bin/data/db
sudo chown -R `id -un` /usr/local/bin/data/db
Running "brew update" returns:
brew update
Updated 1 tap (homebrew/cask).
==> Updated Casks
brave-browser
brew install mongodb-community-shell
Fixed the problem for me.
Solved it by manually installing the mongodb community files and db tools using the website instead. Then copying them into /usr/local/bin. Then ignoring the app permissions whenever calling mongo or related commands in the terminal through System Preferences > Security & Privacy > General.
After googling I found out that mongoimport and the other features have to be installed separately: https://www.mongodb.com/try/download/database-tools
Followed by copying those bin files after extracting them into the same /usr/local/bin directory
Not sure why its' not working through homebrew though
This worked for me, I was having same issue on mongodb-community#4.4
brew reinstall mongodb-community#4.4
On terminal something like this will appear during reinstallation.
copy highlighted path with echo
echo 'export PATH="/opt/homebrew/opt/mongodb-community#4.4/bin:$PATH"' >> ~/.zshrc
Now open another terminal and start mongodb services
brew services restart mongodb/brew/mongodb-community#4.4
write mongo on terminal and here we fly
If you installed the mongodb via Homebrew. Need to add the mongo path in your bash_profile.
Edit the bash_profile vi ~/.bash_profile
Add the below line in EOF export PATH=$PATH:/usr/local/opt/mongodb-community#4.2/bin
After the edit bash_profile. Close all terminals and open them again. mongo command start works.
In addition to #ramesh-babu-t-b 's answer, https://stackoverflow.com/a/68407530/1279516, the issue could also be that your MongoDB installation did add mongod to your path, but the installation happened within the current shell session, and so your shell doesn't have the updates to the PATH variable yet.
In this case, only his last step is still necessary - Open a new console window and retry the mongod command.

Why can I not install Node with Homebrew?

I was able to download homebrew successfully. However, whenever I use 'brew install node' , I am getting the error message:
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/systemtap/tapset/node.stp
/usr/local/share/systemtap/tapset is not writable.
You can try again using:
brew link node
I have also tried 'brew link node' which results in:
Error: Could not symlink share/systemtap/tapset/node.stp
/usr/local/share/systemtap/tapset is not writable.
Can anyone help please?
The solution is in the official troubleshooting page of Homebrew. You have to give Homebrew the right to write inside /usr/local. To do this the official command to run is:
cd /usr/local && sudo chown -R $(whoami) bin etc include lib sbin share var opt Cellar Caskroom Frameworks
If you have not installed applications in /usr/local that rely on specific permissions, you can also run:
sudo chown -R $(whoami) /usr/local/*

mongo db (mongodb.service) failed, status 14

I am experiencing the following problem using mongodb.
This is the error, when I check the status:
Screenshot of the error (mongodb.service, status 14)
Screenshot of code in the mongod.config file
Screenshot of the log file
I have tried uninstalling mongodb following every step from the website and install everything again and when I check the status I still get the same error. I have posted the screenshot of the error.
I am using MacBook pro if this matters.
Would really appreciate, if someone can help me fix this.
By changing the owner to monogdb user of
/var/lib/mongodb and /tmp/mongodb-27017.lock has worked for me.
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
It seems from the log you have a unclean shutdown before. Or, it could also indicates that mongod is already running.
First, make sure mongod is not running already
ps aux | grep mongod
If it's not, remove the file:
rm /tmp/mongodb-27017.sock
Then try systemctl start mongod to start MongoDB again.
After rebooting in the command line,it fixed to problem,don’t know why after stopping mongo and uninstalling and installing it didn’t fix the problem, but after reboot everything is working fine.
This worked for me on Ubuntu 18.04
Go to the TMP directory: cd /tmp
Check if you have the mongodb sock file: ls *.sock
Change the user:group permission: chown mongodb:mongodb <YOUR_SOCK>
Start MongoDB: sudo service mongod start
Check the MongoDB status: sudo service mongod status
If this does not work you can try
sudo reboot
Please see here : https://medium.com/#gabrielpires/mongodb-ubuntu-16-04-code-exited-status-14-aws-lightsail-problem-417ffc78cb11
I had a similar issue and even though the permissions were all okay, the service failed to start. I had a look at the mongodb log
sudo tail -40 /var/log/mongodb/mongod.log
It said that the database was shutdown unexpectedly and needed to be repaired. I ran
sudo mongod --repair --config /etc/mongod.conf
This fixed the database, but now changed the permissions. You will need to do the chown steps again.
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
Start the mongod service. It would be up & running now.
Same happended with CentOS Stream 8
the user for mongodb service is mongo and group is also mongo
sudo chown mongod:mongod /tmp/mongodb-27017.sock
Resolved, after checking the logfile, showing mongodb-27017.sock failed to start.
I have a similar issue. Was a SELinux blocking the normal execution.
So, I did:
# ausearch -c 'mongod' --raw | audit2allow -M my-mongod
# semodule -X 300 -i my-mongod.pp
and then:
$ sudo systemctl start mongod
and check:
sudo systemctl status mongod
chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock

PostgreSQL installation failed on Ubuntu 14.04

I recently uninstalled postgresql from my computer. I tried to install it again but I faced some problems. I tried to fully uninstall it again like this:
I found al the packages related to postgres:
$ dpkg -l | grep postgres
Them I removed all the packages and related folders :
$ sudo apt-get --purge remove postgresql postgresql-9.3 postgresql-client-9.3 postgresql-client-common postgresql-common postgresql-contrib-9.3
$ sudo rm -rf /var/lib/postgresql/
$ sudo rm -rf /var/log/postgresql/
$ sudo rm -rf /etc/postgresql/
I've tried to install it again, but after the installation I can't access postgres user.
$ sudo apt-get install postgresql postgresql-contrib
$ sudo -i -u postgres
sudo: unable to change directory to /home/postgres: No such file or directory
If I access root I can access postgres but this is what happens:
$ sudo su -
$ su - postgres
No directory, logging in with HOME=/
postgres#rafael-pc:/$ psql
psql (9.3.9)
Type "help" for help.
postgres=# \q
could not save history to file "/home/postgres/.psql_history": No such file or directory
I have no idea what is happening. I've tried to uninstall it many times but I always have some kind of error when I install it back.
Just a guess here, but it sure looks to me like the problem is that there isn't a /home/postgres directory. I'm not sure what may have happened in your uninstall process to remove that, but it looks like that's the cause of the error in both of the steps you list.
Can you try this (or some approximation of these steps, which create that directory and make sure it's owned by the postgres user)?
# sudo mkdir /home/postgres
# sudo chown postgres /home/postgres

Brew error: Could not symlink, path is not writable

When I try to install a library with homebrew (brew install aLibrary), I got the following error:
Could not symlink lib/pkgconfig/aFile
/usr/local/lib/pkgconfig is not writable.
What should I do?
There are several questions and answers (1,2,etc.) concerning this brew error, this is an attempt to make a general question as suggested here.
As explained here by Rick:
Start with brew doctor which will show you errors with your brew setup.
You might see something like this: "Warning: /usr/local/lib/pkgconfig isn't writable."
It will give you the advice that: "You should probably chown /usr/local/lib/pkgconfig".
This means: sudo chown -R $(whoami) /usr/local/lib/pkgconfig
Then you will need to link the files with this: brew link yourLibrary
If this does not work hopefully the output of brew doctor will give you enough to continue the search.
Giant Elk had a great suggestion and this is how I fixed my issue, which in my opinion is the cleanest. Users should not change permissions unless they know the ramifications.
Output your installed packages (via brew) to a text file:
brew list > brewlist.txt
Uninstall brew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
Re-install brew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Re-install previous packages (edit list if you do not need all packages):
brew install $(< brewlist.txt )
Use the following.
$ brew doctor
message will display error links to prune. If any found, run next option.
$ brew prune
once these are removed, proceed to link them agian
$ brew link python
I uninstalled brew, re-installed, then the issues went away.
You should simply give the permission to your account by running this command on terminal.
sudo chown -R $(whoami) (path)
In your case:
sudo chown -R $(whoami) lib/pkgconfig/aFile /usr/local/lib/pkgconfig

Resources