Is there a way to install programs through bash? [duplicate] - bash

This question already exists:
home brew says no such file or directory [closed]
Closed 7 months ago.
I'm fairly new to bash's sudo commands etc. I recently wanted to upgrade my psql and when i tried to brew install it, it was not happening. Turns out that brew itself had stopped supporting my old version of mac os in 2021. Meaning I couldn't do anything with brew. Only first time when i ran brew update it gave me the following:
$brew update
warning: unable to unlink .gitignore: Permission denied
warning: unable to unlink .yardopts: Permission denied
warning: unable to unlink CODEOFCONDUCT.md: Permission denied
warning: unable to unlink CONTRIBUTING.md: Permission denied
warning: unable to unlink LICENSE.txt: Permission denied
warning: unable to unlink SUPPORTERS.md: Permission denied
error: unable to unlink old 'README.md' (Permission denied)
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master
'brew update' , 'brew install' or 'brew doctor' - nothing worked. after that when ever i try, i get No such file or directory:
$brew install postgresql#12
-bash: /usr/local/bin/brew: No such file or directory
Wanted to know if bash has commands that can be used to upgrade my psql version? if yes, how?

To me it seems more like a permission problem, have you tried prepending sudo to brew update?

Related

I can't uninstall brew on MacOS Apple Silicon

Like it is mentioned here https://docs.brew.sh/FAQ#how-do-i-uninstall-homebrew I typed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" but it doesn't seem to work...
When I type afterwards which brew it returns /usr/local/bin/brew
and when I type again /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
It displays :
/bin/bash: line 236: /opt/homebrew/bin/brew: No such file or directory
Failed to locate Homebrew!
So I don't know what to do to uninstall brew.
My ultimate goal is to not getting this error when I try to install a brew package :
Error: Cannot install in Homebrew on ARM processor in Intel default
prefix (/usr/local)! Please create a new installation in /opt/homebrew
using one of the "Alternative Installs" from:
https://docs.brew.sh/Installation You can migrate your previously
installed formula list with: brew bundle dump
I now have a Mac with Apple Silicon but I used to have a Intel Mac.
EDIT 1 : I took a quick look at the uninstall.sh script here https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh
It seems that my problem is induced by my os installation because I did it from an Intel-based MacOS time machine backup. The problem is the uninstall.sh script is programed to uninstall homebrew according to the current os. So this script can only uninstall the ARM homebrew that I need and can't uninstall the Intel homebrew I try to get rid of...
Maybe I should try to just change the line of code that detect I have a ARM CPU to make the script think I have a Intel-based Mac but I don't know if it could bring chaos in my computer...
I'm surprised there's not a lot of answers about this problem since I don't think I'm the only one to have switched from Intel-based Mac to ARM-based Mac with Time Machine.
EDIT 2 : I tried to uninstall Homebrew with a command of my own arch -x86_64 ./uninstall_brew.sh (I have no idea if it's not DANGEROUS) but I don't know if it worked well...
Here is the output of the command :
user#MacBook-Pro % arch -x86_64 ./uninstall_brew.sh
Warning: This script will remove:
/Users/user/Library/Caches/Homebrew/
/usr/local/Caskroom/
/usr/local/Cellar/
/usr/local/bin/brew -> /usr/local/bin/brew
Are you sure you want to uninstall Homebrew? This will remove your installed packages! [y/N] y
==> Removing Homebrew installation...
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
/usr/local/share/info/dir: Permission denied
Warning: Failed to delete /usr/local/Caskroom
rm: /usr/local/Caskroom: Permission denied
Warning: Failed to delete /usr/local/Cellar
rm: /usr/local/Cellar: Permission denied
==> Removing empty directories...
Password:
==> /usr/bin/sudo /usr/bin/find /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/var /usr/local/Caskroom /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks -name .DS_Store -delete
==> /usr/bin/sudo /usr/bin/find /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/var /usr/local/Caskroom /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks -depth -type d -empty -exec rmdir {} ;
==> Homebrew uninstalled!
The following possible Homebrew files were not deleted:
/usr/local/.com.apple.installer.keep
/usr/local/Frameworks/
/usr/local/Homebrew/
/usr/local/bin/
/usr/local/etc/
/usr/local/git/
/usr/local/include/
/usr/local/lib/
/usr/local/man/
/usr/local/opt/
/usr/local/remotedesktop/
/usr/local/sbin/
/usr/local/share/
/usr/local/var/
You may wish to remove them yourself.
Try running: PATH=/usr/local/bin:$PATH arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
Found the answer here: https://github.com/Homebrew/discussions/discussions/3437
I encounter similar issue on my M1 MBP, and I found that changing the uninstall path in the script may work.
First, I download a local copy of the uninstalling script
curl -O https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh
Then run the script locally and set the path to /user/local(which is the default path of homebrew on intel Mac)
/bin/bash uninstall.sh --path=/usr/local
but it completed with 2 warnings I'm not sure what they are
Warning: Failed during: /usr/bin/sudo rmdir /usr/local
Warning: Homebrew partially uninstalled (but there were steps that failed)!
To finish uninstalling rerun this script with `sudo`.
The following possible Homebrew files were not deleted:
/usr/local/Cellar/
/usr/local/Frameworks/
/usr/local/Homebrew/
/usr/local/bin/
/usr/local/etc/
/usr/local/include/
/usr/local/lib/
/usr/local/opt/
/usr/local/sbin/
/usr/local/share/
/usr/local/texlive/
/usr/local/var/
You may wish to remove them yourself.
Either way, I delete those files manually.
(This is my first time to answer something on stack overflow. Hope this help!)

Doing brew update fatal: unable to access '.git/config': Permission denied mac os catalina

[Screenshot]
1fatal: unable to access '.git/config': Permission denied
warning: unable to access '.git/config': Permission denied
fatal: unable to access '.git/config': Permission denied
warning: unable to access '.git/config': Permission denied
fatal: unable to access '.git/config': Permission denied
I'm doing command brew update
I have the ZSH shell installed as well and I'm using Iterm also the same error on original terminal
After your fresh homebrew installation, you should always run sudo chown -R $(whoami) $(brew --prefix)/* to do the one-time permission setup.
This is because homebrew is trying to setup the brew repo for brew in your local.

brew update fails with "Permission denied" error

I have been trying to upgrade my brew installation on Mac and it always fails with the following error:
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied # dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied # dir_s_mkdir - /usr/local/Frameworks
I do not want to run brew as sudo, but is there a way to fix this error? I'm not able to install Python3 which is my ultimate goal. Is there another way to install Pythion3 on Mc other than brew? Is there any resolution for this problem here?
EDIT: I tried to remove python3 and tried to re install it again and this time it fails with some other message:
==> Pouring python-3.6.5.high_sierra.bottle.1.tar.gz
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied # dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied # dir_s_mkdir - /usr/local/Frameworks
Try to change owner of /usr/local.
if you use macOS High Sierra or higher try this command:
sudo chown -R $(whoami) $(brew --prefix)/*
if you use macOS Sierra or lower:
sudo chown -R $(whoami) /usr/local
In Mac OSX Mojave, installing Python3, I solved this issue by the following:
sudo mkdir /usr/local/Frameworks
sudo chown -R user:group /usr/local/Frameworks/
brew link python
Where user and group are specified as set by the OS. You can find out what user/group values should be by doing:
ls -al /usr/local
And then python3 was successfully installed:
> python3
Python 3.7.2 (default, Feb 12 2019, 08:15:36)
[.Clang 10.0.0 (clang-1000.11.45.5)] on darwin

brew.rb Permission denied

I was trying to brew update when I got suddenly a permission error:
/usr/local/bin/brew: line 28: /usr/local/Library/brew.rb: Permission denied
/usr/local/bin/brew: line 28: exec: /usr/local/Library/brew.rb: cannot execute: Undefined error: 0
I also tried sudo brew update, but without any luck.
What can I do?
The way that worked for me was to do as #happylookout suggested.
cd /usr/local
git fetch origin
git reset --hard origin/master
However, you may get a permissions error such as:
error: unable to unlink old 'bin/brew' (Permission denied)
error: unable to unlink old 'share/man/man1/brew.1' (Permission denied)
fatal: Could not reset index file to revision 'origin/master'.
To fix this, you need to run the last command above with sudo:
sudo git reset --hard origin/master
Now you should be able to run brew update without errors.
Had the same problem just now and solved it by updating the whole thing via git:
cd /usr/local
git fetch origin
git reset --hard origin/master
You could try running this
sudo chown -R $(whoami) /usr/local
I uninstalled brew and reinstalled it. Fixed the problem.

Failing while running `brew install

I am trying to re-install Nokogiri dependencies with homebrew following the steps described here. I had nokogiri working fine before, but had to remove macports to make some space on my mac.
Running into errors at the first step:
$ brew install libxml2 libxslt
Warning: Your Xcode (3.2.2) is outdated
Please install Xcode 3.2.6.
==> Downloading ftp://xmlsoft.org/libxml2/libxml2-2.8.0.tar.gz
Warning: Failed to create the file
Warning: /Library/Caches/Homebrew/libxml2-2.8.0.tar.gz
0.0%
curl: (23) Failed writing body (0 != 1448)
Error: Download failed: ftp://xmlsoft.org/libxml2/libxml2-2.8.0.tar.gz
Any idea how to fix this?
Is the warning about Xcode version significant?
The relevant message above seemed to be Warning: Failed to create the file.
Tried to create the /Library/Caches/Homebrew/libxml2-2.8.0.tar.gz file manually, and got a Permission denied error.
Changed the ownership of the folder to my username:group with
sudo chown <username>:<group> /Library/Caches/Homebrew/
With that change, the brew install step worked successfully!
Note: The answers to brew install mongodb error: Cowardly refusing to `sudo brew install' Mac OSX Lion helped in figuring out the problem.

Resources