/usr/local/bin No such file or directory - macos

/usr/local/bin is not found on my mac computer. I already ran
defaults write com.apple.Finder AppleShowAllFiles TRUE
and still not /usr/local/bin. I am trying to install ssh-copy-id by following https://github.com/beautifulcode/ssh-copy-id-for-OSX but it fails when trying to move ssh-copy-id to /usr/local/bin. Any ideas on how to fix this?

You should be able to create it yourself by executing sudo mkdir -p -m 775 /usr/local/bin from the terminal. If /usr/local/bin is not in your $PATH environmental variable, you can update it by appending export PATH=$PATH:/usr/local/bin to the file $HOME/.bash_profile. Close your current terminal, and open a new one for testing.
UPDATE: If you have brew installed, you can just run brew install ssh-copy-id.

Related

zsh: permission denied: /Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m MacOS

Python3.6 are installed in /Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m
But >>python3.6 does not recognize
Try: >>/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m
Get: zsh: permission denied: /Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m
If you installed from python.org using the .pkg file, it should have symlinked:
/usr/local/bin/python3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
(check this by ls -Alh /usr/local/bin | grep "python3.6").
If the symlink doesn't exist you can create it:
ln -s /usr/local/bin/python3.6 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
If the symlink does exist but calling python3.6 still doesn't work then check that /usr/local/bin is in your PATH with echo $PATH | grep "/usr/local/bin".
If you don't see :/usr/local/bin: highlighted in the output you need to add this directory to your path in your ~/.zshrc file, with the following:
echo 'export PATH=$PATH:/usr/local/bin' >> ~/.zshrc
be sure to either open a new terminal once you've saved your .zshrc or source ~/.zshrc it.
Install python3.6:
brew unlink python
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb

How to use Homebrew on a Multi-user MacOS Sierra Setup

I have a Mac that is shared between two engineers. Both have separate user accounts. Both need to run brew update and brew install... occasionally.
How do I set this up without getting errors like:
/usr/local must be writable!?
Yeah, I could have UserA take over the permissions of /usr/local every time he wants to use brew (and same with UserB), but that seems like a lot of unnecessary trouble.
You can also change the group permissions to admin or another group that both of your users are in:
chgrp -R admin /usr/local
chmod -R g+w /usr/local
Original source: https://gist.github.com/jaibeee/9a4ea6aa9d428bc77925
UPDATE:
In macOS High Sierra you can't change the owner, group or permissions of /usr/local. So you have to change the group and permissions of the subfolders:
chgrp -R admin /usr/local/*
chmod -R g+w /usr/local/*
UPDATE September 2018, High Sierra 10.13.6
Determine the path of the brew prefix, ie. the path that will be used to store files related to working with homebrew
Check that all users on the system who need access to brew are in the admin group
Optional Add a user to the admin group if a user needs access to brew
Will require access / privileges to use the sudo command
Set the brew prefix path to be recursively owned by the admin group
Set the brew prefix path to be recursively writable by all users who are in the admin group
Verify the permissions of the brew prefix
brew 🍻
echo $(brew --prefix)
echo $(groups $(whoami))
sudo dseditgroup -o edit -a $(whoami) -t user admin
sudo chgrp -R admin $(brew --prefix)
sudo chmod -R g+rwX $(brew --prefix)
ls -lah $(brew --prefix)
Every answer that tries to hack permissions, or use sudo is wrong.
Do not use sudo and do not share a single brew installation across user accounts.
The correct answer per the Homebrew docs is to use zero or one global brew installation on a machine, and for all other users install a local version of brew.
This is especially important on Mac, but works on Linux too.
This can be done by one of the following approaches
Git approach: doing a git checkout of the source repo
Untar-anywhere approach: expanding a tarball into some directory – owned by your user
Git approach
For the git approach you'll need to clone brew.
Arbitrarily choosing my user home directory for my checkout:
cd $HOME
git clone https://github.com/Homebrew/brew.git
./brew/bin/brew tap homebrew/core
Untar-Anywhere Approach
As documented at docs.brew.sh, run this command in your home directory, which will create ~/brew.
cd $HOME
mkdir brew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C brew
Finishing up
For either installation method, you'll need to change your PATH to prefer the new brew bin directory, adding something like this to your shell's dot file.
export PATH=$HOME/brew/bin:$PATH >> ~/.zshrc # or ~/.bashrc
Then running this to reload and test
exec $SHELL
which brew # see that brew is found in your path
Since this is a new installation, you have to install all your desired brew packages (again).
Install homebrew for each user
According to the brew documentation you can install it inside each User Home folder
That way all packages are going to stay inside your user folder, and will not be visible or affect other users. As a good side effect if you delete that user, no trash is left behind on your system. So system wide pollution is minimised.
This comes at the cost of more storage being used, if you install the same package for multiple users. Just something to be aware if you have a very small SSD.
Instructions
If you currently have brew installed on your system globally, I recommend uninstalling brew first. (You can see where brew is installed running which brew)
If you don't have Command Line Tools installed, you have to run this first:
xcode-select --install
Open terminal and Run:
MacOS Catalina 10.15 or newer:
cd $HOME
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
echo 'export PATH="$HOME/homebrew/bin:$PATH"' >> .zprofile
MacOS Mojave 10.14 or older:
cd $HOME
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
echo 'export PATH="$HOME/homebrew/bin:$PATH"' >> .bash_profile
Close the Terminal window
Open Terminal again, and run this to ensure your installation is correct:
brew doctor
Done!
Disabling auto update
This is not required
I also find useful to disable brew to update all packages before every time you install something.
MacOS Catalina 10.15 or newer
echo 'HOMEBREW_NO_AUTO_UPDATE=1' >> $HOME/.zprofile
MacOS Mojave 10.14 or older
echo 'HOMEBREW_NO_AUTO_UPDATE=1' >> $HOME/.bash_profile
EDIT: Please use the answer by Vitim, it's the correct one :)
Hacky workaround solution for macOS Mojave 10.14
This is a edited version of user4815162342's answer, which didn't work for me out-of-the-box.
In System Preferences, go to Users & Groups, click the lock symbol in the bottom left corner to unlock user/group creation, then create a new group called brew-usergroup. Add all users who work with brew to the group (like in the attached screenshot from a german macOS).
In terminal, do this:
echo $(brew --prefix)
echo $(groups $(whoami))
sudo dseditgroup -o edit -a $(whoami) -t user brew-usergroup
sudo chgrp -R brew-usergroup $(brew --prefix)/*
sudo chmod -R g+rwX $(brew --prefix)/*
ls -lah $(brew --prefix)
Note that this doesn't change rights of brew folders anymore (like in other answers), it changes subfolders/files of brew folders.
brew install should now work fine without errors.
The above works fine, but if you want new files to automatically inherit those permissions, set an ACL which gets inherited (otherwise only the user that pours a bottle can remove it). Found hints how to do this here: https://gist.github.com/nelstrom/4988643
As root run once (assuming all users of group "admin" should have access):
cd /usr/local
/bin/chmod -R +a "group:admin allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" Homebrew Caskroom Cellar bin
/usr/bin/chgrp -R admin Homebrew Caskroom Cellar bin
/bin/chmod -R g+rwX Homebrew Caskroom Cellar bin
ls -lae .
the -e on ls shows ACLs.
Update: now I use specific directories (see above) as it failed (sth. like out of memory)
Homebrew is not designed to be used by different Unix users. From the FAQ:
If you need to run Homebrew in a multi-user environment, consider creating a separate user account especially for use of Homebrew.
The chmod solution is not viable unless you ensure that every newly created file in the Homebrew prefix also has the group write permission, which is not the case with the default umask – or unless you keep running that chmod command every time a program writes to the Homebrew prefix.
Maintaining separate Homebrew installations for each user do sort the permissions issues but will create a number of other issues, which is why it's not recommended by Homebrew:
However do yourself a favour and use the installer to install to the default prefix. Some things may not build when installed elsewhere. One of the reasons Homebrew just works relative to the competition is because we recommend installing here. Pick another prefix at your peril!
To ease the official recommendation of using a dedicated account for Homebrew, you can use sudo to easily impersonate that user account. Assuming you named that user homebrew:
sudo -H -u homebrew brew update
-H makes sure HOME is set to the homebrew user home (e.g. /Users/homebrew) so that Homebrew can do its housekeeping there.
-u homebrew tells sudo to impersonate the homebrew user account instead of the default of root.
Here is the official answer of the Homebrew maintainer.
In addition to it I suggest to do 3 more steps. Suppose you have an admin user niki who owns the /usr/local/* dir and you are logged in as another admin user niki_at_work.
Create ~/brew.sh with these contents:
#!/bin/bash
comm="brew $#"
su niki -c "$comm"
chmod +x ~/brew.sh
Add this alias to .zshrc or equivalent: alias brew="~/brew.sh"
Now you can brew from niki_at_work like always (it will ask for niki's password):
brew update
brew install swiftlint
If you want to use a dedicated admin user for brew ex. brewadmin you should first chown brew dirs:
sudo chown -R brewadmin:admin /usr/local/*
The best solution is to add a sudoers record to allow unprivileged user 'joe' to execute any 'brew' related command as the administrative user.
Create a file at /etc/sudoers.d/joe with following content:
joe ALL=(administrator) NOPASSWD: /usr/local/bin/brew
Then you can run brew like this:
sudo -Hu administrator brew install <smth>
The above solutions didn't work for me. But running the command below worked for me.
sudo chown -R $(whoami) $(brew --prefix)/*
Source: https://github.com/Homebrew/brew/issues/3228#issuecomment-333858695

How to run a script file on Mac?

I have searched on how to run a script file on Mac but nothing works for me.
Every time I tried sudo script-name the terminal responds with
-bash: /Users/macuser/Desktop/tesseract-3.01: is a directory
The file I want to run is called start and it's located in tesseract-3.01 directory on the desktop.
simply do
/Users/macuser/Desktop/tesseract-3.01/start
or if it's actually called start.sh
/Users/macuser/Desktop/tesseract-3.01/start.sh
you might also want to do
chmod +x /Users/macuser/Desktop/tesseract-3.01/start.sh
to change the script to be executable before you run the script
sudo /Users/macuser/Desktop/tesseract-3.01/start
You have to indicate the script name, but it looks like you were only specifying the directory.
You could also cd to the directory and then run it like so:
cd /Users/macuser/Desktop/tesseract-3.01
sudo ./start
Try
sudo ./Users/macuser/Desktop/tesseract-3.01/start.sh
or
cd /Users/macuser/Desktop/tesseract-3.01
then
sudo ./start.sh

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

how to set environment variable for root user

I'm Mac user.
I want to set PYTHONPATH env for root. so
$ sudo su -
# vi ~/.profile
and add to file 'export PYTHONPATH=/mypythonlib'
then
# env
I can see this line
PYTHONPATH=/Users/simpnet2/projects/meiji/src/hershey
but..
when I use sudo command, cannot find that
$ sudo env
.. there's no PYTHONPATH
My program has to run with sudo command and needs PYTHONPATH.
If you use sh try /etc/profile, bash try /etc/bashrc and if you use zsh try /etc/zshenv.
You can make PYTHONPATH visible to sudo be editing your sudoers file. Notice you should ONLY do this through visudo as explained here.
You should try sudo -i which will simulate logging in as root and source the ~root/.profile.
As of 10.8.5, putting my environment statements in the .profile path in the home of the root user (/var/root) worked. after quitting bash and coming back to the root user prompt with 'su -', I could see my new path, etc. with the 'env' command and my MacPorts installationw orking correctly.
MacBook-Pro:~ root# cat /var/root/.profile
export MANPATH=/opt/local/share/man:$MANPATH
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
MacBook-Pro:~ root# which port
/opt/local/bin/port
Well, in other Linux system, it is also right that 'sudo' does not use local environment variable. But you can declare the temporary environment variable along with 'sudo' command.
For example, in your case, you can add 'PYTHONPATH=/mypythonlib' in your command 'sudo env', and the final command is:
sudo PYTHONPATH=/mypythonlib env
You can also read this article: Using sudo. You can see how 'sudo' keep or ignore user-defined environment variables.
In the case of logging in as a normal user and invoking "su - root" I found that Mac OS 10.8.5's bash was ignoring .profile and .bash_profile; I was unable to change root's $PATH by editing those files. What did work was editing /etc/paths. After exiting the root shell and entering again with "su - root" the new path was present.

Resources