On OSX using sourcetree / git-svn getting "Can't locate SVN/Core.pm in #INC " - macos

I'm using OSX and want get a svn repo into a local git repo using sourcetree.
When I add a bookmark using sourcetree using SVN URL, thus sourcetree knows it's a SVN url, but when I click the clone button, it reports an error like following:
Can't locate SVN/Core.pm in #INC (#INC contains: /usr/local/git/lib/perl5/site_perl /Applications/SourceTree.app/Contents/Resources/git_local/lib/perl5/site_perl /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.4 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .) at /Applications/SourceTree.app/Contents/Resources/git_local/lib/perl5/site_perl/Git/SVN/Editor.pm line 5.
BEGIN failed--compilation aborted at /Applications/SourceTree.app/Contents/Resources/git_local/lib/perl5/site_perl/Git/SVN/Editor.pm line 5.
Compilation failed in require at /Applications/SourceTree.app/Contents/Resources/git_local/libexec/git-core/git-svn line 81.
BEGIN failed--compilation aborted at /Applications/SourceTree.app/Contents/Resources/git_local/libexec/git-core/git-svn line 81.
I don't how to get it through. Can anyone give me a pointer on how to do this?

I hit this missing SVN/Core.pm issue recently with el capitain.
Fix I used was from Paul Schreiber's blog :
sudo mkdir /Library/Perl/5.18/auto
sudo ln -s /Applications/Xcode.app/Contents/Developer/Library/Perl/5.18/darwin-thread-multi‌-2level/SVN /Library/Perl/5.18/darwin-thread-multi-2level
sudo ln -s /Applications/Xcode.app/Contents/Developer/Library/Perl/5.18/darwin-thread-multi‌-2level/auto/SVN /Library/Perl/5.18/auto/
Commenters below, say this worked on sierra and high sierra too.

Or, if you don't have Xcode, just CommandLineTools (this is on ElCapitan 10.11.6):
sudo ln -s /Library/Developer/CommandLineTools/Library/Perl/5.18/darwin-thread-multi-2level/SVN /usr/local/git/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level/SVN
sudo ln -s /Library/Developer/CommandLineTools/Library/Perl/5.18/darwin-thread-multi-2level/auto/SVN /usr/local/git/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level/auto/SVN
If you previously linked some older version or just made a mistake so it gives you: File exists, then you should first do
sudo unlink /usr/local/git/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level/SVN
for whichever file was reported as already existent, of course.
EDIT Dir doesn't exist: (suggested by #rogeriopradoj)
mkdir -p /usr/local/git/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level
EDIT Sierra:
After upgrading to Sierra I lost CommandLineTools, so I just had to reinstall it and everything was back to normal.
This will prompt you to install just the CommandLineTools, not the whole XCode.
xcode-select --install
Hope this helps someone :)

In my case, it is because different versioned perl was installed by brew as dependency of some formula, and override the system's default version.
So the resolution for me is to relieve the overridden as described following.
when type which perl and perl -v, I find it not the system default version:
# locate programs
faner#MBP-FAN:~|⇒ whereis perl
/usr/bin/perl
# locate a program file in the user's path
faner#MBP-FAN:~|⇒ which perl
/usr/local/bin/perl
faner#MBP-FAN:~|⇒ perl -v
This is perl 5, version 26, subversion 1 (v5.26.1) built for darwin-thread-multi-2level
which should be v5.18.2 according to the git svn error messages.
I guess it is because the different versioned perl was installed by brew as dependency of some formula, and override the system default version.
faner#MBP-FAN:~|⇒ brew uses perl --installed
subversion
To prove it, try to move /usr/bin before /usr/local/bin in $PATH, then perl was fallback to the system's default version:
faner#MBP-FAN:~|⇒ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
faner#MBP-FAN:~|⇒ PATH=/usr/bin:$PATH
faner#MBP-FAN:~|⇒ echo $PATH
/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
faner#MBP-FAN:~|⇒ whereis perl
/usr/bin/perl
faner#MBP-FAN:~|⇒ which perl
/usr/bin/perl
faner#MBP-FAN:~|⇒ perl -v
This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)
and perl -V list the #INC just satisfy the Can't locate SVN/Core.pm in #INC requirements:
faner#MBP-FAN:~|⇒ perl -V
Summary of my perl5 (revision 5 version 18 subversion 2) configuration:
#INC:
/Library/Perl/5.18/darwin-thread-multi-2level
/Library/Perl/5.18
/Network/Library/Perl/5.18/darwin-thread-multi-2level
/Network/Library/Perl/5.18
/Library/Perl/Updates/5.18.2
/System/Library/Perl/5.18/darwin-thread-multi-2level
/System/Library/Perl/5.18
/System/Library/Perl/Extras/5.18/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.18
type git svn and everything works well!
faner#MBP-FAN:~|⇒ git svn --version
git-svn version 2.15.1 (Apple Git-101) (svn 1.9.7)

Manage to fix the same issue by changing the first line in /usr/local/Cellar/git/2.29.2/libexec/git-core/git-svn
to
#!/usr/local/bin/perl

Plus to the highest answer,
If you are using souceTree, simply paste command line may not work immediately.
In that case, you may need to check git used in your sourceTree, which should be set as System git.

Xcode 11.4 no longer includes SVN/Core.pm in its Perl bindings!
If you've never installed the commandline tools and Xcode 11.4 is the first version you've run you will see this issue. Running xcode-select --install returns error: command line tools are already installed, use "Software Update" to install updates, which is accurate but non-obvious that your installed commandline tools differ from what you would get if installed outside of Xcode 11.4. The solution is to first remove these, then install the commandline tools using xcode-select.
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

Thanks Marko, I did find that on ElCapitan 10.11.3 I had to symlink to a different area. Not sure why, but it works.
sudo ln -s /Library/Developer/CommandLineTools/Library/Perl/5.18/darwin‌​-thread-multi-2level‌​/SVN /Applications/SourceTree.app/Contents/Resources/git_local/li‌​b/perl5/site_perl/5.‌​18.2/darwin-thread-m‌​ulti-2level/SVN
sudo ln -s /Library/Developer/CommandLineTools/Library/Perl/5.18/darwin‌​-thread-multi-2level‌​/auto/SVN /Applications/SourceTree.app/Contents/Resources/git_local/li‌​b/perl5/site_perl/5.‌​18.2/darwin-thread-m‌​ulti-2level/auto/SVN

I got the same issue on Macos Mojave 10.14.1. Because I used the built-in version of git, and it's too lower(2.19.0). I fixed it by upgrade git to the latest version(2.21.0), and I found 2.19.1 also has no this issue.

The solution for me was to delete the password entry in the OSX key ring app, and have git svn re-create it. My key entry has been created earlier (by svn I suppose), and it seems that git cannot use this key entry (nor fix it nor add a second one).
The long story: I noticed that when unsing "system git" in SourceTree, there seemed to be a problem storing the credentials. When I entered the same git command (that SourceTree is issuing) on the command-line, git kept prompting me for my password each time.
Then I found https://stackoverflow.com/a/39800112/580672
If you are interested, my setup was:
No Xcode, only Command-Line tools (so I adapted the paths as mentioned in a post above ( https://paulschreiber.com/blog/2015/11/09/fixing-git-svn-on-os-x-el-capitan/comment-page-1/#comment-437843 )
Homebrew has svn and perl installed
I had tried with no success:
"embedded git" (yields the #INC error)
"system git" (different error: "Username: Use of uninitialized value $ret in chomp at /usr/local/Cellar/git/2.21.0/share/perl5/Git.pm line 596.")
put usr/bin in front of my PATH as suggested above
force-uninstalled perl in homebrew
All without success. The solution was system git and the key entry, as stated above.

I've found that the best solution is to expand the list of directories in #INC using an export
export PERL5LIB=/Applications/Xcode.app/Contents/Developer/Library/Perl/5.18
Referenced from: https://perlmaven.com/how-to-change-inc-to-find-perl-modules-in-non-standard-locations

Related

Mac command line tools 11.4 no longer has svn

I just updated XCode and the command line tools to 11.4. Now when I run svn it says "svn: error: The subversion command line tools are no longer provided by Xcode". The release notes say "Command line tool support for Subversion — including svn, git-svn, and related commands is no longer provided by Xcode. If you need Subversion or related command line tools the you need to install the Command Line Tools package by running xcode-select --install." I seem to be in a loop here, as the tools are installed. Has anyone experienced this problem and resolved it?
macOS Catalina
I had the same issue after upgrading to Catalina 10.15. It's clearly mentioned in the Apple website that SVN is deprecated in Xcode 11:
You can find it here: https://developer.apple.com/documentation/macos_release_notes/macos_catalina_10_15_release_notes
Command line tool support for Subversion — including svn, git-svn, and related commands — is no longer provided by Xcode.
The solution is to install the standalone Command Line Tools package instead:
sudo rm -rf /Library/Developer/CommandLineTools
followed by:
sudo xcode-select --install
This will replace the bundled Command Line Tools with the standalone package.
If it doesn't work for you then try to install it with brew.
brew install svn
brew is a package manager for MacOS so if you don't have it installed then you can simply install it: https://brew.sh/
macOS Big Sur
I faced the same issue Today (16th November 2020) after upgrading to MacOS Big Sur. I was able to fix it by installing the SVN again using brew install svn command.
If you faced permission errors after running above command, you can fix it by running following command.
sudo chown -R $(whoami) /usr/local/*
brew install svn
in Xcode 11.4. Svn has been removed.
I had same issue from Netbeans and have done the following from command line and now all fine
sudo xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew install svn
Coming from a FreeBSD background we elected to install SVN via MacPorts which is akin to FreeBSD Ports. So basically one would first need to install MacPorts and then install SVN as follows:
sudo port install subversion
Some details -
Install MacPorts: https://www.macports.org/install.php
Install SVN: https://trac.macports.org/wiki/howto/Subversion
It took less than five(5) minutes and works well for us.
I switched to SVNKIT which works very well for my purposes. Since I'm doing a lot of Java development is no drawback for me that SVNKIT is based on Java.
The big advantage is that SVNKIT will still work even if Apple throws SVN out completely.
I found svn still available on my Mac (upgraded from 10.15.x -> Big Sur, including XCode upgrade) in
/Library/Developer/CommandLineTools/usr/bin/svn
In the Apple Developers forum I read the suggestion to make an alias, which worked for me. However, considering svn is being dropped by Apple, this will probably not work on new installs, but it could be useful for those of us that just want it to work for now after upgrading.
alias svn=/Library/Developer/CommandLineTools/usr/bin/svn
Note: I found it easier to just make a symbolic link to svn:
ln -s /Library/Developer/CommandLineTools/usr/bin/svn /usr/local/bin/svn
my mac os version is macOs Catalina 10.15.5,I try
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
brew install svn
but it not work.so I try to install with source code.It's work!
tar xvf subversion-1.14.0.tar.gz
cd subversion-1.14.0
./configure --with-apr=/usr/local/opt/apr --with-apr-util=/usr/local/opt/apr-util
make
now,you can find it in /usr/local/bin/
Based partly on the other answers here, I built from source with this procedure:
Download & unpack svn source tarball (NOT zip file!) from
https://subversion.apache.org/download.cgi
cd subversion-1.14.0
./get-deps (this seems to have downloaded apr and apr-util but not
built them)
cd apr
sudo mkdir /usr/local/opt
(because I did not already have such a directory on a fresh Mac)
./configure --prefix=/usr/local/opt/apr
make
make test
(saw lots of "OK" and "SUCCESS", plus one failure in "testsock")
sudo make install
cd ../apr-util
./configure --prefix=/usr/local/opt/apr-util --with-apr=/usr/local/opt/apr
cd ..
make
./configure --with-apr=/usr/local/opt/apr --with-apr-util=/usr/local/opt/apr-util --with-lz4=internal --with-utf8proc=internal
make
sudo make install
The top instructions (removing the command line tools, xcode-select --install, and brew install svn) worked for me (Monterey, 12.5.1, on an M1 pro). Thanks!
However, after I did the brew install, I had to manually remove the old svn version from /opt/local/bin before the new version would run. (discovered with $ which svn). Might be the result of migrating from the old laptop to the new one.

How do I update zsh to the latest version?

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.

Replace Xcode's git with downloaded latest 1.8.3

I want to use latest version of git (1.8.3).
Currently when I make git --version it shows me git version 1.7.12.4 (Apple Git-37) which was installed together with Xcode I suppose.
I installed newest version but still bash uses Xcode one..
Please advice me how to override xcode git with the path that is installed to usr/local/bin?
Thanks!
Edit ~/.bash_profile and add
alias git=/usr/local/bin/git
Source the bash_profile file or restart bash (source ~/.bash_profile)
See what git --version prints.
I am not sure if this affects XCode. I never use versioning tools in IDEs, I do it from the command line
Or you add /usr/local/bin to $PATH to your bash_profile. I do this with macports or better said macports alters your bash_profile automatically.
export PATH=/usr/local/bin:$PATH
Use a symbolic link to make Xcode use the /usr/local/bin/git instead of its built-in git
cd /Applications/Xcode.app/Contents/Developer/usr/bin/
sudo mv git xcodeGIt
sudo ln -s git /usr/local/git
Disclaimer: typed inline -- but thats how it works. Done it and it works fine for me

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.

override git from Xcode with homebrew version

I've installed XCode and therefore git is there as well. Since i want to have a newer version of git I installed using homebrew.
But the homebrew version of git is never called since my PATH looks like this
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
which means the /usr/bin/git is allways called before /usr/local/bin/git.
Is there a way to change that without changing the PATH?
Xcode is actually using the GIT that is stored in /Applications/Xcode.app/Contents/Developer/usr/bin. The same version of GIT gets installed in /usr/bin when you installed the command line tools as part of Xcode installation. So, you won't be able to change what Xcode is using (unless you are willing to muck with the contents of the Xcode package). If, from a terminal application, you want to use the homebrew-installed GIT then you have two options:
Reference GIT with the full path as /usr/local/bin/git ... For this case you can create an alias like alias mgit=/usr/local/bin/git and then use mgit ... from the terminal
Change the path as PATH=/usr/local/bin:$PATH either in your .bashrc or .zshrc if you use zsh file (or each time you start a terminal at the command line).
Since Xcode hard coded its own version of git which is installed on /Applications/Xcode.app/Contents/Developer/usr/bin/git, I managed to use this work around trick:
change into the Xcode directory:
cd /Applications/Xcode.app/Contents/Developer/usr/bin
rename the Xcode's git like this:
sudo mv ./git ./git-xcode-usr-bin
link my own git which is installed through homebrew:
sudo ln -s /usr/local/bin/git ./git
And I did the same thing with /usr/bin/git
This will acctually link /usr/local/Cellar/git/1.8.0/bin/git (because I'm use git 1.8.0 at the present)
Certainly this may cause some other problems, such as when I upgrade the homebrew's verion git in the future, it would not work for me :( and I have to make a new link then.
I do it like this because I want to solve my own problem here 13177203. And after search StackOverFlow for a long time, I finally got this solution.
If you are using fish shell instead of bash, you can point to your preferred git binary by adding the following to ~/.config/fish/config.fish.
function git
/usr/local/bin/git $argv;
end

Resources