How do I update zsh to the latest version? - terminal

I recently switched to zsh on my Terminal.app on my OS X machine successfully. The version number of zsh is 4.3.11.

If you're using oh-my-zsh
Type omz update in the terminal
Note: upgrade_oh_my_zsh is deprecated

If you have Homebrew installed, you can do this.
# check the zsh info
brew info zsh
# install zsh
brew install --without-etcdir zsh
# add shell path
sudo vim /etc/shells
# add the following line into the very end of the file(/etc/shells)
/usr/local/bin/zsh
# change default shell
chsh -s /usr/local/bin/zsh

If you're not using Homebrew, this is what I just did on MAC OS X Lion (10.7.5):
Get the latest version of the ZSH sourcecode
Untar the download into its own directory then install: ./configure && make && make test && sudo make install
This installs the the zsh binary at /usr/local/bin/zsh.
You can now use the shell by loading up a new terminal and executing the binary directly, but you'll want to make it your default shell...
To make it your default shell you must first edit /etc/shells and add the new path. Then you can either run chsh -s /usr/local/bin/zsh or go to System Preferences > Users & Groups > right click your user > Advanced Options... > and then change "Login shell".
Load up a terminal and check you're now in the correct version with echo $ZSH_VERSION. (I wasn't at first, and it took me a while to figure out I'd configured iTerm to use a specific shell instead of the system default).

As far as I'm aware, you've got three options to install zsh on Mac OS X:
Pre-built binary. The only one I know of is the one that ships with OS X; this is probably what you're running now.
Use a package system (Ports, Homebrew).
Install from source. Last time I did this it wasn't too difficult (./configure, make, make install).

A simple script or execute following commands in terminal
# 1. download (currently the latest version is 5.8) and extract
wget https://sourceforge.net/projects/zsh/files/latest/download -O ./zsh-latest.tar.xz
mkdir zsh-latest
tar -xf zsh-latest.tar.xz -C zsh-latest --strip-components=1
cd zsh-latest
# 2. config, build, install
./configure
make -j4
sudo make install
which zsh
PS: If you fail to build, it probably due to missing necessary libraries. Just install libraries as the error message suggests. E.g, I didn't have ncurses:
sudo apt install ncurses-devel # for Ubuntu
sudo yum install ncurses-devel # for CentOS/Redhat

omz update gave me following error:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
This is an issue with git, where after upgrading to Mac OS Ventura (13.0.1). git command gave me above error.
Solution:
Download and install the 'Command Line Tools' package to fix 'git'
xcode-select --install
This will pop a dialogue box. Select "Install".
More details here: https://apple.stackexchange.com/a/254381
omz update worked successfully after this for me

I just switched the main shell to zsh. It suppresses the warnings and it isn't too complicated.

Related

How to run the Homebrew installer under Rosetta 2 on M1 Macbook

I'm on the M1 MacBook.
This is the error when I try to install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Homebrew is not (yet) supported on ARM processors!
Rerun the Homebrew installer under Rosetta 2.
If you really know what you are doing and are prepared for a very broken experience you can use another installation option for installing on ARM:
https://docs.brew.sh/Installation
So how do I "Rerun the Homebrew installer under Rosetta 2."?
Got an answer from a developer in the Homebrew github https://github.com/Homebrew/brew/issues/9173
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Use this to install packages:
arch -x86_64 brew install <package>
If you have not yet installed Rosetta 2 to emulate Intel CPUs on ARM Macs, you will get the error arch: posix_spawnp: /bin/bash: Bad CPU type in executable. Prompt a Rosetta 2 installation with:
softwareupdate --install-rosetta
I have two instances of brew installed, the Intel version that runs using Rosetta2 and which installs to /usr/local/bin and the Arm version that runs natively and installs to /opt/homebrew/bin. Now it is all working, I do not have to start iTerm using Rosetta.
I have these aliases to reach the two versions.
ibrew='arch -x86_64 /usr/local/bin/brew'
mbrew='arch -arm64e /opt/homebrew/bin/brew'
I have the native version in my path first:
path=( /opt/homebrew/bin /opt/homebrew/opt /usr/local/bin /usr/bin /bin /usr/sbin /sbin /Library/Apple/usr/bin )
Now I can try mbrew search and mbrew install. If they work, I am good to go with a native program. For example:
mbrew install ag
If brew fails I try building from source, with verbose output, e.g.
mbrew install -sv rust
Be warned, this takes a while and may still fail.
If it still fails, (and mbrew install -sv go results in a segmentation fault for me) I have two choices. Use ibrew search and ibrew install to get the Intel build instead, or examine the verbose output and look for problem dependencies. In some cases an install -s on the dependencies is enough to get the native brew to work.
I must stress that native brew always prints this warning
Warning: You are running macOS on a arm64 CPU architecture.
We do not provide support for this (yet).
Reinstall Homebrew under Rosetta 2 until we support it.
So proceed at your own discretion.
For completeness, and assuming you have iTerm2, Rosetta2 and the Xcode command line tools installed, I did this to install brew under Rosetta (with credit to all those who have posted on this page before me):
Copy the installed iTerm2.app application to iRosetta2.app
Press command+I to Get Info for iRosetta.app, click Open Using Rosetta2
Run iRosetta2 and use this command from https://brew.sh
Like so
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)
alias ibrew='arch -x86_64 /usr/local/bin/brew' # put this in ~/.zshrc
And I did this to install native brew, taken from other contributors to Stack Overflow and the Homebrew alternative installation site, using iTerm2 without Open Using Rosetta2
mkdir ~/homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
sudo mv ~/sudo mv homebrew /opt
mbrew='arch -arm64e /opt/homebrew/bin/brew' # for .zshrc
export PATH="/opt/homebrew/bin:/opt/homebrew/opt:$PATH" # also for .zshrc
Edit
Time has passed and I have changed the architecture to arm64e following Fernando García Redondo observation. Now the warning about Arm architecture not supported has gone and Rust and Go install without problems and without compiling from source. I assume the good people at Homebrew have been working hard over Christmas. Thanks!
Edit Feb 21
The Homebrew team have announced that they support Apple silicon. So I wondered if I could delete my aliases and just use brew to install for Apple silicon. The short answer is no! if you run brew from /usr/local without the arch -x86_64, it complains that /usr/local is reserved as the Intel default prefix and using /opt/homebrew is required. So I will retain my two aliases and try mbrew first and only use ibrew if the native brew fails.
Another option is by going into your applications in Finder, select Terminal and press ⌘+I and check the "Open using Rosetta" option.
Sorry if the formatting is off, first time posting a solution.
The easiest way to run Homebrew is with Rosetta 2.
1. Duplicate Your Favourite Terminal for Rosetta
Find your favourite terminal, right-click to duplicate it, and rename it for easier identification. In this example, I'm using the default Terminal app on Big Sur 11.2.1.
Right-click the Terminal Rosetta and go to Get Info to check the Open using Rosetta option.
2. Install Homebrew
Open the rosetta terminal and run the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Running this command will ask you for the password, and then it will provide you with the information of what all it will install and which new directories it will create.
3. Using Homebrew
Once HomeBrew is installed, you can start using it to install your required packages into the M1 Mac.
Run the following command to get brew help:
brew help
To install a package, you can run the following command:
brew install packagename
That’s all about installing and getting started with Homebrew on Apple M1 Macs.
EDIT: Thanks all! Upvote to help other devs! Homebrew 3.0.0 now officially supports Apple Silicon (https://brew.sh/2021/02/05/homebrew-3.0.0/)
After I installed Rosetta, I added an alias so I can use brew install <package> as I would normally.
alias brew='arch -x86_64 brew'
I agree with everyone else in that you need to add the arch -x86_64 in front of the original command so thought to include that alias to help anyone finding this thread in the future
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" worked on my new M1 Mac
Do below
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
alias brew='arch -x86_64 brew'
brew install azure-cli
now try az login. you are good to go
You can change the setting of Terminal to launch it using Rosetta.
Go to your Application/Utilities folder, right click on the Terminal App and check the tick box 'Open using Rosetta'
But to be honest, I have Homebrew installed without Rosetta. Just removed the x86 version yesterday and installed a fresh version without Rosetta.

Problem installing git subrepo on MacOs bash 5

I was trying to install git subrepo on MacOs with bash 5.0.18 installed. When I source .bashrc, I get error message :
The git-subrepo command requires that 'Bash 4+' is installed. It
doesn't need to be your shell, but it must be in your PATH. You appear
to be on macOS. Try: 'brew install bash'. This will not change your
user shell, it just installs 'Bash 5.x'.
Is git subrepo not compatible with bash 5 or is there any solution to make it work?
https://github.com/ingydotnet/git-subrepo
apparently, I can install it using brew with less hassle:
brew install git-subrepo
It should be a PATH issue, as illustrated by ingydotnet/git-subrepo issue 463
I realized there was a part of my path not being specified which caused this issue.

Yosemite and Valgrind

Can you tell me how to install valgrind on yosemite? When I try to install it i get " checking for the kernel version... unsupported (14.0.0)
configure: error: Valgrind works on Darwin 10.x, 11.x, 12.x and 13.x (Mac OS X 10.6/7/8/9) "
There is no official path or update, and I didn't found anything (except http://comments.gmane.org/gmane.comp.kde.devel.bugs/1553705 , but they didn't resolve that problem).
As there's no stable release that supports Yosemite, you can install the latest development version with
brew install --HEAD valgrind
Whilst it may have been the case in past OS X release cycles that Valgrind took a period of time before achieving reasonable feature support, basic OS X 10.10 support is already available in Valgrind trunk due to significant work on pre-release Yosemite.
From the mailing list:
There has been some effort recently to improve Valgrind's support for
Yosemite. If you develop on Mac OS, you might like to try out the
trunk (svn co svn://svn.valgrind.org/valgrind/trunk) and report any
breakage you get. Support for Yosemite is good enough that at least
one large graphical application (Firefox) runs OK. Support for the
previous release, 10.9 (Mavericks), is also substantially improved.
Note that the work has targetted 64 bit processes only. 32 bit might
work, and probably better on Mavericks, but I suspect it will be
increasingly problematic on Yosemite due to Valgrind's 32 bit x86
instruction set support not having progressed passed SSSE3.
Julian Seward
http://sourceforge.net/p/valgrind/mailman/message/33047840/
Full disclosure: I'm one of the new Valgrind developers who contributed patches to support OS X 10.10
Valerio's svn workflow will download every branch which is time and resource consuming. A better procedure is to download just the trunk:
svn co svn://svn.valgrind.org/valgrind/trunk valgrind
cd valgrind
./autogen.sh
./configure
make
make install
Here is my take on it. I more or less had a clean mac with xcode installed.
Got it compiling and running with the following:
# build/install autoconf/automake/libtool so that 'autogen' works
curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz
tar -xzf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure && make && sudo make install
cd ..
curl -OL http://ftpmirror.gnu.org/automake/automake-1.14.tar.gz
tar -xzf automake-1.14.tar.gz
cd automake-1.14
./configure && make && sudo make install
cd..
curl -OL http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz
tar -xzf libtool-2.4.2.tar.gz
cd libtool-2.4.2
./configure && make && sudo make install
cd ..
svn co svn://svn.valgrind.org/valgrind/trunk valgrind
cd valgrind
./autogen.sh
# important: configure-params, otherwise make ends in errors
./configure -disable-tls --enable-only64bit --build=amd64-darwin
make
# sudo, otherwise it fails due to permissions
sudo make install
Note that callgrind_control (from valgrind-3.11.0 SVN) doesn't appear to work on OS X, looks like a perl-script and the commandline tool which it runs (vgdb -l) prints something 'unexpected' which that script doesn't correctly parse ( so it won't be able to find the other process running with valgrind ).
Alternatively, the perl script just calls vgdb, we can also directly do that ( just figure out your process-id manually):
vgdb --pid=2858 instrumentation on
Worked for me on 10.10.1 :
svn co svn://svn.valgrind.org/valgrind
cd valgrind
./autogen.sh
./configure
make
make install
All of the solutions listed here failed for me. What finally ended up working was to use mac ports.
sudo port install valgrind-devel
Here's how to install it using alternative sources besides the official svn (because it seems to be intermittently available).
https://crispyappstudiosblog.wordpress.com/2015/07/07/installing-valgrind-on-osx-yosemite/
1) Navigate to this git mirror of the svn and download the latest
available version: http://repo.or.cz/w/valgrind.git
2) You need VEX as well, so grab the latest version here:
http://repo.or.cz/w/vex.git
3) Extract both of them. Put the entire contents of the VEX folder
into a folder called VEX in the top level of the valgrind directory.
cd to the valgrind directory, and execute the following:
Run ./autogen.sh
Run ./configure
Run make
Run sudo make install
Test it out by running valgrind --version You should be running at
least 3.11.0 SVN for it work on Yosemite.
I installed it on my mac by installing homebrew and then running this 3 commands in the terminal.
brew update
brew doctor
brew install --HEAD valgrind
PS: I have Os X El Capitan (10.11) but this should work with previous versions too.
I finally got Valgrind to work on my OSX El Capitan 10.11.12.
User Kalmiya's answer worked for me first after I installed Xcode commandline tools.
Type this in the terminal:
xcode-select --install
Now follow Kalmiya's post, step by step.
https://stackoverflow.com/a/30366798/3633475
Here is another take on the svn install. The previous ones did not work for me, since I needed to have automake and autoconf installed, which I did not, even though I had the latest version of the Xcode command line tools installed.
I got the following from this site. I also had to link automake and autoconf after doing brew install automake and brew install autoconf by doing brew link automake and brew link autoconf for this to work.
# Check out their repo...
$ svn co svn://svn.valgrind.org/valgrind/trunk valgrind-trunk
# and hop into it.
$ cd valgrind-trunk
# You need to have autoconf and automake installed to build Valgrind
# This example uses Homebrew to install these dependencies
# (MacPorts should also work)
# (Permission error? add sudo!)
$ brew install automake
$ brew install autoconf
# run autogen.sh in valgrind-trunk
$ ./autogen.sh
# Tricky, there are some hard wired paths in the Valgrind sources.
# You need to symlink the mach folder in your XCode SDK to /usr/include/mach
# Be sure to use the proper Xcode SDK "MacOSX10.10.sdk" in the path!
$ ln -sv /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/mach /usr/include/mach
# Run configure + set install paths in valgrind-trunk
$ ./configure --prefix=/usr/local
# Run Make and make install (permission error? add sudo!) in valgrind-trunk
$ make
$ make install
# Check it works
$ valgrind --version
valgrind-3.11.0.SVN
I have used kalmiya's instructions to build valgrind as a conda package for OSX Yosemite. For those who work with anaconda/conda, just do
conda install -c https://conda.binstar.org/groakat valgrind
Side-note:
I needed to install the command line tools as described below to get valgrind compiled.
https://stackoverflow.com/a/30471647/2156909
I got valgrind on Yosemite compiled, but had to use a hack to do so. While I think you should be using xcode-select install to get all command line tools (after which valgrind should make properly), but if you don't want to do this (eg. size of Xcode tools too big), you can also get the Darwin OSX code and copy the following files to /usr/include/mach
mach_vm.defs
task.defs
thread_act.defs
vm_map.defs
This allowed a clean compile and install, although note it is a rather slack hack.

how to install libX11 on OSx 10.9?

I am trying to install ROOT (cern.root.ch). When I run ./configure , I get a message that libX11 is missing and must be installed.
I did some research and found that I need to install
) XQuartz (I already have the latest version.)
) Command line tools in Xcode.
I tried installing Command Line Tools from apple's developer website. The installation goes through smoothly but how do I know whether it has been installed? I still get libX11 missing error with root's configure command.
I also tried xcode-select --install and it once went through smoothly and then later again gives error saying this package is no longer maintained - or something of that sort.
I understand I may have multiple installations... But I am still facing the problem of not having libX11 and not being able to install ROOT.
Thanks,
Hershal.
This link and the one referenced in it suggests you use homebrew (brew) to install it
$ ruby <(curl -fsS https://raw.github.com/mxcl/homebrew/go)
$ brew doctor
Remember to add the Homebrew directory to your PATH by adding the directory (found with brew --prefix) to your .bashrc, .zshrc or whatever shell file you’re using (.bashrc is the OS X default). We’ll also add the XQuartz binaries to the PATH in case anything needs them in the future.
export PATH=/usr/local/bin:/opt/X11/bin:$PATH
Start a new Terminal session to pick up the changes.
Now that Homebrew is installed, we can use it to install the required dependencies. Each may take some time as Homebrew generally compiles from source.
$ brew install gfortran # Fortran compiler
$ brew install python # Python interpreter
$ brew install pcre # Regular Expressions library
$ brew install fftw # Fast Fourier Transforms
$ brew install cmake # Cross-platform make
install root
$ brew tap homebrew/science
$ brew install --with-cocoa root
You don't say whether you have installed XCode as well as the commandline tools but I think you will need it

How to check if XCode command line tools are installed?

I have a macbook pro with OS X 10.8.2. XCode is installed. I know this as it appears in the Applications directory. There are also the xcodebuild and xcode-select files in /usr/bin. I need to know if the command line tools is installed. Is there a command for it? hat can I do to see if XCode CLT is installed and if yes to find the version installed?
10.15 Catalina Update:
See Yosemite Update.
10.14 Mojave Update:
See Yosemite Update.
10.13 High Sierra Update:
See Yosemite Update.
10.12 Sierra Update:
See Yosemite Update.
10.11 El Capitan Update:
See Yosemite Update.
10.10 Yosemite Update:
Just enter in gcc or make on the command line! OSX will know that you do not have the command line tools and prompt you to install them!
To check if they exist, xcode-select -p will print the directory. Alternatively, the return value will be 2 if they do NOT exist, and 0 if they do. To just print the return value (thanks #Andy):
xcode-select -p 1>/dev/null;echo $?
10.9 Mavericks Update:
Use pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
10.8 Update:
Option 1: Rob Napier suggested to use pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI, which is probably cleaner.
Option 2: Check inside /var/db/receipts/com.apple.pkg.DeveloperToolsCLI.plist for a reference to com.apple.pkg.DeveloperToolsCLI and it will list the version 4.5.0.
[Mar 12 17:04] [jnovack#yourmom ~]$ defaults read /var/db/receipts/com.apple.pkg.DeveloperToolsCLI.plist
{
InstallDate = "2012-12-26 22:45:54 +0000";
InstallPrefixPath = "/";
InstallProcessName = Xcode;
PackageFileName = "DeveloperToolsCLI.pkg";
PackageGroups = (
"com.apple.FindSystemFiles.pkg-group",
"com.apple.DevToolsBoth.pkg-group",
"com.apple.DevToolsNonRelocatableShared.pkg-group"
);
PackageIdentifier = "com.apple.pkg.DeveloperToolsCLI";
PackageVersion = "4.5.0.0.1.1249367152";
PathACLs = {
Library = "!#acl 1\\ngroup:ABCDEFAB-CDEF-ABCD-EFAB-CDEF0000000C:everyone:12:deny:delete\\n";
System = "!#acl 1\\ngroup:ABCDEFAB-CDEF-ABCD-EFAB-CDEF0000000C:everyone:12:deny:delete\\n";
};
}
10.10 Yosemite
Below are a few extra steps on a fresh Mac that some people might need. This adds a little to #jnovack's excellent answer.
Update: A few other notes when setting this up:
Make sure your admin user has a password. A blank password won't work when trying to enable a root user.
System Preferences > Users and Groups > (select user) > Change password
Then to enable root, run dsenableroot in a terminal:
$ dsenableroot
username = mac_admin_user
user password:
root password:
verify root password:
dsenableroot:: ***Successfully enabled root user.
Type in the admin user's password, then the new enabled root password twice.
Next type:
sudo gcc
or
sudo make
It will respond with something like the following:
WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.
To proceed, enter your password, or type Ctrl-C to abort.
Password:
You have not agreed to the Xcode license agreements. You must agree to
both license agreements below in order to use Xcode.
Press enter when it prompts to show you the license agreement.
Hit the Enter key to view the license agreements at
'/Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf'
IMPORTANT: BY USING THIS SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THE
FOLLOWING APPLE TERMS:
//...
Press q to exit the license agreement view.
By typing 'agree' you are agreeing to the terms of the software license
agreements. Type 'print' to print them or anything else to cancel,
[agree, print, cancel]
Type agree. And then it will end with:
clang: error: no input files
Which basically means that you didn't give make or gcc any input files.
Here is what the check looked like:
$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
10.9 Mavericks
With Mavericks, it is a little different now.
When the tools were NOT found, this is what the command pkgutil command returned:
$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
To install the command line tools, this works nicely from the Terminal, with a nice gui and everything.
$ xcode-select --install
http://macops.ca/installing-command-line-tools-automatically-on-mavericks/
When they were found, this is what the pkgutil command returned:
$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 5.0.1.0.1.1382131676
volume: /
location: /
install-time: 1384149984
groups: com.apple.FindSystemFiles.pkg-group com.apple.DevToolsBoth.pkg-group com.apple.DevToolsNonRelocatableShared.pkg-group
This command returned the same before and after the install.
$ pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI
No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.
Also I had the component for the CLT selected and installed in xcode's downloads section before, but it seems like it didn't make it to the terminal...
To check if command line tools are installed run:
xcode-select --version
// if installed you will see the below with the version found in your system
// xcode-select version 1234.
If command line tools are not installed run:
xcode-select --install
In macOS Catalina, and possibly some earlier versions, you can find out where the command line tools are installed using:
xcode-select -p a.k.a. xcode-select --print-path
Which will, if it is installed, respond with something like:
/Library/Developer/CommandLineTools
To find out which version you have installed there, you can use:
xcode-select -v a.k.a. xcode-select --version
Which will return something like:
xcode-select version 2370.
However, if you attempt to upgrade it to the latest version, assuming it is installed, using this:
xcode-select --install
You will receive in response:
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Which rather erroneously gives the impression you need to use Spotlight find something called 'Software Update'. In actual fact, you need to continue in the Terminal, and use this:
softwareupdate -i -a a.k.a. softwareupdate --install --all
Which tries to update everything it can and may well respond with:
Software Update Tool
Finding available software
No new software available.
To find out which versions of the different Apple SDKs are installed on your machine, use this:
xcodebuild -showsdks
On macOS Sierra (10.12) :
Run the following command to see if CLT is installed:
xcode-select -p
this will return the path to the tool if CLT is already installed. Something like this -
/Applications/Xcode.app/Contents/Developer
Run the following command to see the version of CLT:
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
this will return version info, output will be something like this -
package-id: com.apple.pkg.CLTools_Executables
version: 8.2.0.0.1.1480973914
volume: /
location: /
install-time: 1486372375
I think the simplest way which worked for me to find Command line tools is installed or not and its version irrespective of what macOS version is
$brew config
macOS: 10.14.2-x86_64
CLT: 10.1.0.0.1.1539992718
Xcode: 10.1
This when you have Command Line tools properly installed and paths set properly.
Earlier i got output as below
macOS: 10.14.2-x86_64
CLT: N/A
Xcode: 10.1
CLT was shown as N/A in spite of having gcc and make working fine and below outputs
$xcode-select -p
/Applications/Xcode.app/Contents/Developer
$pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
$brew doctor
Your system is ready to brew.
Finally doing xcode-select --install resolved my issue of brew unable to find CLT for installing packages as below.
Installing sphinx-doc dependency: python
Warning: Building python from source:
The bottle needs the Apple Command Line Tools to be installed.
You can install them, if desired, with:
xcode-select --install
Go to Applications > Xcode > preferences > downloads
You should see the command line tools there for you to install.
From a programmatic perspective the Homebrew folks have a check for the existence of various files to determine if the command line tools are installed. Currently it always checks for /Library/Developer/CommandLineTools/usr/bin/git and will also check for /usr/include/iconv.h if the OS version is 10.13 or below.
Open your terminal and check to see if you have Xcode installed already with this:
xcode-select -p
in return, if you get this:
/Library/Developer/CommandLineTools
That means you have that Xcode is installed.
Another way you can check would you if you have "HomeBrew" installed you can use the following command to see if you have Xcode and the version:
brew config
And finally, if you don't have the Xcode follow this link to download the Xcode from the Appstore. Xcode from the App Store.
Good Luck.
to use on a bash script:
if ! command -v xcode-select &> /dev/null
then
echo "\t xcode was not found! You need to manually install it :/ "
else
echo "xcode is installed, checking other IOS build tools"
fi
Some contributors write when xcode-select -p or xcode-select -print-path would return /Library/Developer/CommandLineTools that this would mean that CLTs are installed. This is not really correct as xcode-select can be used to switch among multiple Xcode installations and CLTs. Aforementioned commands merely return which development environment is currently in use, i.e. which Xcode or whether CLTs are currently in use. The returned path to some also installed Xcode may then be returned and you cannot deduce from this whether CLTs are actually installed or not.
Moreover, as Apple recommends even to simply delete CLTs by deleting the directory /Library/Developer/CommandLineTools before a reinstallation it may well be that aforementioned commands return /Library/Developer/CommandLineTools despite the fact that they are no longer installed. Even the use of pkgutil is no warranty that CLTs are really installed if directory /Library/Developer/CommandLineTools was previously simply deleted.
The most robust technique is therefore xcode-select --install and the macOS will invite you to install CLTs via an alert, which you can cancel if you wish only to learn about the presence or absence of CLTs. If you prefer a method without any GUI, e.g. in a shell script, then testing for the presence of directory /Library/Developer/CommandLineTools and pkgutil returning "No receipt..." as described above are AFAIK a way to go. E.g. code similar to following
theCLTversion=`pkgutil --pkg-info=com.apple.pkg.CLTools_Executables 2>/dev/null | grep version`
if [ -d /Library/Developer/CommandLineTools ] && [ "$theCLTversion" != "" ]; then
echo "CLTs $theCLTversion installed"
else
echo "CLTs seem not to be installed"
fi
may do the job. However, I have not tested above snippet to lead to correct results on older systems prior to OS X 10.11.6 (El Capitan).
Because Xcode subsumes the CLI tools if installed first, I use the following hybrid which has been validated on 10.12 and 10.14. I expect it works on a lot of other versions:
installed=$(pkgutil --pkg-info=com.apple.pkg.CLTools_Executables 2>/dev/null || pkgutil --pkg-info=com.apple.pkg.Xcode)
Salt with awk to taste for branching logic.
Of course xcode-select -p handles the variations with a really short command but fails to give the detailed package, version, and installation date metadata.
% xcode-select -h
Usage: xcode-select [options]
Print or change the path to the active developer directory. This directory
controls which tools are used for the Xcode command line tools (for example,
xcodebuild) as well as the BSD development commands (such as cc and make).
Options:
-h, --help print this help message and exit
-p, --print-path print the path of the active developer directory
-s , --switch set the path for the active developer directory
--install open a dialog for installation of the command line developer tools
-v, --version print the xcode-select version
-r, --reset reset to the default command line tools path
Run the command xcode-select --install
The answer for this is very simple actually, and for any application for that matter, just try to reinstall it,
It will either install it or it will show you the error, you can stop the process if you don't want.

Resources