How to update zsh in Mac OSX Sierra? - terminal

I am trying to update ZSH in Mac OSX Sierra to 5.3.1
I have used brew to update it with following commands.
$brew install zsh
$sudo dscl . -create /Users/$USER UserShell /usr/local/bin/zsh
Now after rebooting, when I run tests, this is what I have:
$dscl . -read /Users/$USER UserShell
UserShell: /usr/local/bin/zsh
$which zsh
/bin/zsh
$zsh --version
zsh 5.2 (x86_64-apple-darwin16.0)
$echo $SHELL
/usr/local/bin/zsh
So I don't understand why iTerm2 and my regular Mac terminal won't pickup new location for zsh (/usr/local/bin/zsh), and why is it still showing previous version (5.2). I also run this to confirm brew installed new version.
$ls -la /usr/local/bin/zs*
lrwxr-xr-x 1 myusername admin 27 Mar 25 18:48 /usr/local/bin/zsh -> ../Cellar/zsh/5.3.1/bin/zsh
lrwxr-xr-x 1 myusername admin 33 Mar 25 18:48 /usr/local/bin/zsh-5.3.1 -> ../Cellar/zsh/5.3.1/bin/zsh-5.3.1
I am also running oh-my-zsh, which I have already updated to the latest version.

Almost certainly your $PATH does not contain /usr/local/bin, or it has /bin listed before /usr/local/bin, so your "which zsh" and "zsh --version" commands run /bin/zsh. Try adding this to your .zshrc, for example:
export PATH="/usr/local/bin/:$PATH"
You could also try to check the version of zsh in $SHELL:
$SHELL --version

Related

source /.bash_profile command provide error

I run the command source ~/.bash_profile and get the following error:
$ source ~/.bash_profile
-sh: /Users/chaklader/.sdkman/contrib/completion/bash/sdk: line 37: syntax error near unexpected token `<'
-sh: /Users/chaklader/.sdkman/contrib/completion/bash/sdk: line 37: ` done < <(curl --silent "${SDKMAN_CANDIDATES_API}/candidates/all")'
The login shell that I use is bin/sh:
Whats the issue here and how to solve it?
This is how I solved the issue with the provided steps:
Install Homebrew from the docs on their homepage
Install Git using Homebrew (optional, but nice to have a more up-to-date git)
brew install git
Now install bash:
brew install bash
Add this install of bash to the allowed shells list:
echo '/usr/local/bin/bash' | sudo tee -a /etc/shells;
Homebrew installs things to /usr/local/Cellar/ by default, then symlinks any binaries to /usr/local/bin, so you've now got the latest bash sitting at /usr/local/bin/bash
Finally, change your shell to use this new one:
chsh -s /usr/local/bin/bash
Open a new terminal window/tab, and run these commands to double-check your work:
$ echo $SHELL
/usr/local/bin/bash
$ echo $BASH_VERSION
5.1.8(1)-release
This also solved the issue for running the source ~/.bash_profile whenever I open a new window in the terminal.
Reference:
The answer is from here How do I install Bash >= 3.2.25 on Mac OS X 10.5.8? by user jeffbyrnes

zsh profile path is not reflected.. in terminal in Mac OS 11.2.3

I have installed mysql, trying to set path.
but somehow it does not reflect.
Is not Mysql compatible for zsh by any chance?
% brew list| grep mysql
mysql#5.7
echo 'export PATH="/usr/local/opt/mysql#5.7/bin:$PATH"' >> ~/.bash_profile
% echo 'export PATH="/usr/local/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
% source ~/.bash_profile
then
% mysql --version
zsh: command not found: mysql
You're using zsh in your terminal, so you need to add export PATH="/usr/local/opt/mysql#5.7/bin:$PATH" into your ~/.zshrc file.
If you don't have that file, do touch ~/.zshrc then add that to your Zsh config file.
Alternatively, if you want to switch back to Bash, just do chsh -s $(which bash) (without sudo to only take effect on current logged-in user) and then restart your shell.

Brew is installed but not identified as a command inside postinstall script of `pkgbuild` (MacOS)

I have a small shell script that installs Brew if it is not already installed.
#!/bin/bash -v
which -s brew
if [[ $? != 0 ]] ; then
# Install Homebrew
echo "Installing Brew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
echo "I don't think brew is installed..."
else
brew update
fi
The script runs fine when I run it as a standalone shell script. So I tried to create a package using the pkgbuild utility. But once inside the package the same script fails to identify Brew as a command, even though Brew is installed.
Things that I have tried so far:-
I enabled install logs and I can see
Sep 29 22:48:32 installd[80453]: ./postinstall:
/tmp/PKInstallSandbox.42j7tU/Scripts/org.mybinary.0.0.4.sDKM7K/postinstall:
line 16: brew: command not found
Used absolute path of the Brew binary /usr/local/bin/brew instead. This gave me a different but, nevertheless, still an error.
Sep 30 10:01:22 installd[90276]: ./postinstall: Error: Running Homebrew as root is extremely dangerous and no longer supported.
Sep 30 10:01:22 installd[90276]: ./postinstall: As Homebrew does not drop privileges on installation you would be giving all
Sep 30 10:01:22 installd[90276]: ./postinstall: build scripts full access to your system.
What am I missing?
Thanks!

What is the correct setup for Brew + Zsh + Oh My Zsh on multiple admin users on Mac OS X?

My question is what would be a good way to run two admin accounts for developing in regards to running Homebrew, Zsh and Oh My Zsh and configuring the .zshrc file?
My reasoning for this is that I recently started a new job and would like to use my Mac with two accounts, both of which will be admins and both of which I will require devtools so as to keep my work life/dev and personal life/dev cleanly separated. I just erased my hard drive and cleanly installed OS X 10.12.3 and created two Admin accounts.
I've had a shot at setting it up however keep getting permission errors whenever I switch accounts and run terminal, usually specific to zsh completions.
My steps:
Install Homebrew on both users /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)".
Install zsh with brew brew install zsh and change to it chsh -s /bin/zsh.
Install oh my zsh with curl via sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)".
run sudo chown -R $(whoami):admin /usr/local.
Then I've tried a whole mess of things which I'll refrain from adding as I believe they may only lead others down a dark path.
Although this step is safe to run as root, I still recommend running the installation as non-root user to prevent catastrophic problems with root switching shell while the shell isn't working. superuser shell should never be changed.
Here's the proper way to install oh-my-zsh for multiple users.
Step 1: Ensure umask is not stricter than 022. If not set it to 022.
$ umask 022
Step 2: set and export ZSH with the destination path where the shared oh-my-zsh will be installed.
export ZSH=/usr/local/.zsh/oh-my-zsh
Step 3: Create the parent directory and make it owned by the user installing the scripts.
$ sudo mkdir /usr/local/.zsh
$ sudo chown ${USER} /usr/local/.zsh
Step 4: Run the installer.
$ bash -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Step 5: Change ownership of the installation path back to root.
$ sudo chown -R root /usr/local/.zsh
Step 6: Update location of ZSH in ${ZSH}/templates/zshrc.zsh-template
$ sudo sed -i 's|export ZSH=.*|export ZSH='${ZSH}'|' ${ZSH}/templates/zshrc.zsh-template
(Optional)
Step 7: Disable auto update. This is recommended as the installation is now owned by root.
$ sudo sed -i 's/# DISABLE_AUTO_UPDATE="true"/DISABLE_AUTO_UPDATE="true"/' ${ZSH}/templates/zshrc.zsh-template
From here on, each user can copy ${ZSH}/templates/zshrc.zsh-template as ~/.zshrc
Whilst #alvits answer may have been correct I was unable to get it to work for me. I however, was able to get it to work by doing the following.
Install Homebrew (check https://brew.sh/ for up to date command):
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install Zsh with Homebrew:
brew install zsh
Close terminal and reopen with ZSH as default shell:
Install Oh My Zsh as root user
sudo su
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Close terminal to exit root user mode.
Install Oh My Zsh as each admin (therefore install on both users):
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
That stopped all the auto-completions and permission errors for me. I believe this to be overkill and that there would be a way with symlinks however this way is easy.

oh-my-zsh does not start on mac

I installed oh-my-zsh as suggested in http://ohmyz.sh/.
FYI,
[~]$ zsh --version
zsh 5.0.8 (x86_64-apple-darwin15.0)
[~]$ echo $SHELL
/bin/zsh
[~]$ ls .oh-my-zsh/
LICENSE.txt cache lib oh-my-zsh.sh templates tools
README.md custom log plugins themes
Only when I type "zsh" then I can see the oh-my-zsh prompt like:
[~]$ zsh
➜ ~
Also, I tried to change my default shell to zsh:
[~]$ chsh -s /bin/zsh
Changing shell for myUserName.
Password for myUserName:
chsh: no changes made
How can I use directly oh-my-zsh whenever I start mac terminal?
Not only in System Pref>User and Group>...>User profile's shell settings, but also in Mac's terminal>Preference>ChosenProfile>Shell section, I had to change /bin/bash to /bin/zsh. after that, it works! Thank you, #RemyJ!
You have to change the default shell to zsh.
To do so use the following command.
chsh -s /bin/zsh
restart your terminal
I took it from here.
These were the steps I followed when I installed zsh.
I hope it will help you as well.
Run the following in the terminal:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Also, I tried to change my default shell to zsh:
[~]$ chsh -s /bin/zsh
try
chsh -s $zsh
that worked fine for me
I had a similar issue but I resolved it by executing the command chsh -s /bin/zsh in the terminal,then navigated to
Terminal -> Preferences -> General window
and changed the Shells open with: option to Default login shell while the command (complete path) set to /bin/zsh.This should solve your problem.

Resources