How to update Xcode from command line
Asked Answered
P

23

594

I am trying to update Xcode from the command line. Initially I tried running:

 xcode-select --install

which resulted in this message:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

So the question remains, is there a way to update Xcode from the command line?

Prudenceprudent answered 5/1, 2016 at 17:14 Comment(4)
@RohitPradhan does that work?Prudenceprudent
@psjv ...not tried yet,Transcription
So obviously you can install from the app store... However I have a hunch that using a terminal command will be faster and more effecient than using the appstore (GUI?). Can anyone build on this idea? I put GUI in paranthesis because i dont know if im using the right terminology.Dinny
The ehow link in Rohit Pradhan's answer should be removed. As of 2022-02-13, it redirects to an unrelated site (itstillworks[.]com that's flagged by a few scanners for malware... virustotal.com/gui/url/… and urlvoid.com/scan/itstillworks.comPlatitudinize
C
851

What you are actually using is the command to install the Xcode command line tools - xcode-select --install. Hence the error message you got - the tools are already installed.

The command you need to update Xcode is softwareupdate command [args ...]. You can use softwareupdate --list to see what's available and then softwareupdate --install -a to install all updates or softwareupdate --install <product name> to install just the Xcode update (if available). You can get the name from the list command.

As it was mentioned in the comments here is the man page for the softwareupdate tool.

2019 Update

A lot of users are experiencing problems where softwareupdate --install -a will in fact not update to the newest version of Xcode. The cause for this is more than likely a pending macOS update (as @brianlmerritt pointed out below). In most cases updating macOS first will solve the problem and allow Xcode to be updated as well.

Updating the Xcode Command Line Tools

A large portion of users are landing on this answer in an attempt to update the Xcode Command Line Tools. The easiest way to achieve this is by removing the old version of the tools, and installing the new one.

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

A popup will appear and guide you through the rest of the process.

Claqueur answered 5/1, 2016 at 17:38 Comment(17)
Hmm, for me for some reason update is listed in App Store, but not listed in command line.Bhatt
--list and --install -a +1Luzluzader
@GinoPane Same. softwareupdate --list said no updates even though App Store showed an update for Xcode.Cringle
So the answer is there is no way to update Xcode by command line? And the workaround is to trigger updates for the entire system by running softwareupdate --install -a? What if you don't want to update OS X itself?Boneblack
Upon testing, softwareupdate --install -a does not even update Xcode, so the answer is entirely wrong it seems.Boneblack
Ran softwareupdate -i -r to install the [recommended] install only, which was the Command Line Tools. It Downloaded twice, installed once, then completed. Seeing that it didn't solve the problem, I reran softwareupdate --list and the recommendation persisted. In AppStore, the Software Update had disappeared, then reappeared. Upon doing it through AppStore, I was prompted to accept user terms. After accepting, it seemed to work. Repeated running softwareupdate --list and it showed up as still recommended...Cabalism
restarting fixedCabalism
You can also try rebooting and then 'sudo xcode-select -r' which will reset the path used for the tools.Asa
Finding available software No new software availableHeddle
this did not list Xcode even thought it is installed.Oxyacid
problem solved with the command: sh sudo rm -rf /Library/Developer/CommandLineTools xcode-select --install Godinez
As near as I can tell, the advice for xcode-select has not worked since before the update was written. xcode-select thinks it is installed even if you remove the directory.Jemmy
sudo rm -rf /Library/Developer/CommandLineTools xcode-select --install works like a charm for meTolerable
A word of warning. Removing the CommandLineTools folder left my system in a broken state where I could no longer install the package using xcode-select. The only way to re-install was to get the installer from developer.apple.com/download/more. After that I could run softwareupdate --all --install --force to get the latest version.Hone
I followed this, but rm -rf personally stresses me out, so I would like to propose the safer method of open /Library/Developer and moving the CommandLineTools directory to the trash in finder so there's a way of making a typo with rm -rf and recovery from the trash is feasible.Monotone
7 years later and on macOS 13.2.1 this (still) worked for me. Thanks.Cageling
This worked for me! After doing this I still needed to set the path to sudo xcode-select -s /Library/Developer/CommandLineTools but it's all good. Thanks.Glimmer
M
328

I had the same issue and I solved by doing the following:

  1. removing the old tools ($ sudo rm -rf /Library/Developer/CommandLineTools)
  2. install xcode command line tools again ($ xcode-select --install).

After these steps you will see a pop to install the new version of the tools.

Maletta answered 14/12, 2017 at 0:16 Comment(17)
Thanks man, this solution works for me too. I spent a whole day trying to get past this.Burchett
@Maletta Isn't removing the entire CommandLineTools folder risky?Soilasoilage
@AryanVenkat why should it be risky? You can reinstall them anytime you like.Maletta
This appeared to work for me: the commands ran without errors, the popup ran to completion, and a new /Library/Developer/CommandLineTools directory was installed. However, the new directory was also out of date (from Xcode 7.3 instead of the current 9.4), so it didn't solve my problem. I ended up searching for developer tools on developer.apple.com/download/more and downloading Command_Line_Tools_macOS_10.13_for_Xcode_9.4.1 from there.Boson
I could only remove /Library/Developer/CommandLineTools by adding a sudo so it became sudo rm -rf /Library/Developer/CommandLineToolsSolvency
I also believe removing the whole directory is risky. Therefore I simply renamed it then issued the install instruction.Emunctory
This doesn't answer the question "How to update xcode from command line" as you can't see pop ups if you are using a terminal only.Usanis
@Usanis The agreement popup will just appear outside the terminal when you run the commandTanana
@Maletta I found sudo rm -rf $(xcode-select -print-path) in github.com/nodejs/node-gyp/blob/master/macOS_Catalina.md docs, so you don't need to remove all command line tools as this seems overkillStancil
If this answer doesn't work for you, try checking if you are actually have Xcode installed. So if you ran rm -rf /Library/Developer/CommandLineTools, but you can still see some version when running /usr/bin/xcodebuild -version, then chances are that you have Xcode installed, and you need to uninstall it.Reluctivity
Sorry, have to downvote - doesn't work at all on Catalina. # mv /Library/Developer/CommandLineTools /Library/Developer/CommandLineTools-AppleSucks # xcode-select --install xcode-select: error: no developer tools were found, and no install could be requested (perhaps no UI is present), please install manually from 'developer.apple.com'.Darrelldarrelle
@Darrelldarrelle do you have command line tools in the first place? I assume not, which means you need to download them from developer.apple.com just like the message says.Maletta
I do indeed have them. I suspect I would have had quite a difficult time moving the install directory if I didn't actually have them installed.Darrelldarrelle
This message # xcode-select --install xcode-select: error: no developer tools were found, and no install could be requested (perhaps no UI is present), please install manually from 'developer.apple.com'. says the opposite though. Try to install them again.Maletta
I got this popup message on Catalina: "Can’t install the software because it is not currently available from the Software Update server."Segal
@DrumM try again later, maybe Apple servers have problems.Maletta
Thanks man, after multiple iteration , the issue is solved. I am able to run the command.Secularism
E
82

I encountered the same issue when I uninstalled the complete version of Xcode to reinstall the CLI version. My fix was:

sudo xcode-select -s /Library/Developer/CommandLineTools

Exacting answered 7/1, 2018 at 4:57 Comment(2)
sometimes the brute force way is the easiest and least complex way (esp true in AppleLand) - however still ended up with an older versionQuestionable
After upgrading a device to Catalina, I wasn't able to install cocoapods until doing this. But it seems to have led to further issues, with xcodebuild requiring xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance. I then had to run sudo xcode-select -r to reset the command line tools path.Fivefinger
S
38

After installing Command Line Tools (with xcode-select --install), type:

sudo xcode-select --switch /Library/Developer/CommandLineTools/

You should be able to run git now:

10:29 $ git --version
git version 2.17.2 (Apple Git-113)
Septime answered 1/2, 2019 at 12:35 Comment(7)
This saved my life - this works in 2019 as the other answers no longer workErdei
I can confirm, this is working for me in the latest version of Mac Catlina (10.15.4 (19E287))Bazan
Worked for me also. Thanks 🙏Curtcurtail
Works in Big Sur version 11.2.2Selfdetermination
Worked for me also. Thanks 🙏Acropolis
so this command by itself upgrades xcode command line tools? sudo xcode-select --switch /Library/Developer/CommandLineTools/ . I"m writing a script to update xcode cmd line tools on a schedule ( e.g daily ) which brought me to this post.Boyhood
This also fixed the error I was getting from pyenv install (configure: error: C compiler cannot create executables).Sparing
V
28

I got this error after deleting Xcode. I fixed it by resetting the command line tools path with sudo xcode-select -r.

Before:

navin@Radiant ~$ /usr/bin/clang
xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist
Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
See `man xcode-select` for more details.

navin@Radiant ~$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

After:

navin@Radiant ~$ /usr/bin/clang
clang: error: no input files
Valenza answered 15/11, 2017 at 20:12 Comment(3)
This fixed it for me. I also deleted Xcode and ran into the error above. While I did try to reinstall just the command line tools using the suggestions in other answers, this is what ultimately resolved the issue.Biotin
Exactly same situation and this worked like a charm. Thanks!Cruz
I deleted Xcode and ran into the same problem, and only this answer resolved the issue.Polyester
H
21

Just type the commands

cd  /Library/Developer/CommandLineTools/Packages/;
open macOS_SDK_headers_for_macOS_10.14.pkg

Reference: https://forums.developer.apple.com/thread/104296

Hindermost answered 17/4, 2019 at 16:37 Comment(2)
I can't say that this is the correct answer by itself, as I also tried numerous other solutions provided here, but it was only after using this solution that the problem was solved, thanks!Cranberry
This package has to exist before this can work. In my version of Xcode it doesn't. (macOS 10.15 after upgrade)Ethnic
P
20

I am not sure why this was so tricky for me.

sudo xcode-select --install

Did nothing for me.

softwareupdate --all --install --force

Did nothing for me.

I had to do things in the following order

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

This installed a newer xcode, but not latest.

Then I did

softwareupdate --all --install --force

and they updated completely.

Pulverable answered 20/2, 2022 at 12:48 Comment(2)
This worked on macOS Monterey v 12.3.1Nelidanelie
Worked for me with Monterey 12.6Halberd
J
13
$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install
Jewish answered 22/8, 2019 at 4:21 Comment(3)
When adding an answer to an older question with existing answers it is useful to point out what new aspect your answer addresses, and also to address if the passage of time and the release of new version has an impact on the answer.Crowned
Confirmed this works on Mac OS Catalina beta. It launches an installation window to download the required software after you approve access.Septal
Confirmed this does not work on OS Catalina. Or High Sierra. Or Sierra... (sample size: entire department)Jemmy
A
13

I was facing the same problem, resolved it by using the following command.

sudo xcode-select -s /Library/Developer/CommandLineTools

After running the above command then xcode-select -p command showed the following.

/Library/Developer/CommandLineTools

Araucanian answered 10/8, 2020 at 7:12 Comment(3)
Searched all over and you helped me .!Tiernan
Not sure why, but after running the first answer's commands, and then this one it started working for meStopwatch
This should be the accepted answer.Ligula
U
11

@Vel Genov's answer is correct, except when the version of Xcode can't be updated because it is the latest version for your current version of Mac OS. If you know there is a newer Xcode (for example, it won't load an app onto a device with a recent version of iOS) then it's necessary to first upgrade Mac OS.


Further note for those like me with old Mac Pro 5.1. Upgrading to Mojave required installing the metal gpu (Sapphire AMD Radeon RX 560 in my case) but make sure only HDMI monitor is installed (not 4K! 1080 only). Only then did install Mojave say firmware update required and shut computer down. Long 2 minute power button hold and it all upgraded fine after that!


Catalina update - softwareupdate --install -a won't upgrade xcode from command line if there is a pending update (say you selected update xcode overnight)

Unbelief answered 24/9, 2017 at 8:10 Comment(0)
B
8

Xcode::Install is a simple cli software that allow you to install/select a specific Xcode version.

You can install it using gem install xcode-install
Then you will be able to install a specific version with xcversion install 9.4.1
And if you have more than one version installed, you can switch version with xcversion select 9.4

You can find more information at https://github.com/KrauseFx/xcode-install

Bipartite answered 16/8, 2018 at 6:34 Comment(1)
Best answer here.Catamenia
J
8

I am now running OS Big Sur. xcode-select --install, and sudo xcode-select --reset did not resolve my issue, neither did the recommended subsequent softwareupdate --install -a command. For good measure, I tried the recommended download from Apple Downloads, but the Command Line Tools downloads available there are not compatible with my OS.

I upvoted the fix that resolved for me, sudo xcode-select --switch /Library/Developer/CommandLineTools/ and added this post for environment context.

Journalese answered 14/1, 2021 at 19:11 Comment(0)
B
8

I was able to update via CLI using:

softwareupdate --list --verbose

and then

softwareupdate -i Command\ Line\ Tools\ for\ Xcode-13.2
Bonaparte answered 16/2, 2022 at 20:56 Comment(0)
E
3

I was trying to use the React-Native Expo app with create-react-native-app but for some reason it would launch my simulator and just hang without loading the app. The above answer by ipinak above reset the Xcode CLI tools because attempting to update to most recent Xcode CLI was not working. the two commands are:

rm -rf /Library/Developer/CommandLineTools
xcode-select --install

This process take time because of the download. I am leaving this here for any other would be searches for this specific React-Native Expo fix.

Embolus answered 16/10, 2018 at 7:53 Comment(0)
L
3

I was faced with this today after an update from Xcode (App Store on Mac) updated my Xcode.

My SourceTree wouldn't allow me to do a merge conflict. In Xcode I found that Command Tools was NOT selected. I selected it, however still no dice as I was getting the same message of:

I performed the command:

softwareupdate --list

which gave me a list of products, including THREE (3) versions of CommandLine Tools Software Update Tool

Finding available software Software Update found the following new or updated software:

  • Label: Command Line Tools for Xcode-13.2 Title: Command Line Tools for Xcode, Version: 13.2, Size: 577329K, Recommended: YES,
  • Label: SFSymbolsAuto-3.3 Title: SF Symbols, Version: 3.3, Size: 169368K, Recommended: YES,
  • Label: Command Line Tools for Xcode-13.3 Title: Command Line Tools for Xcode, Version: 13.3, Size: 718145K, Recommended: YES,
  • Label: Command Line Tools for Xcode-13.4 Title: Command Line Tools for Xcode, Version: 13.4, Size: 705462K, Recommended: YES,

my version of Xcode is 13.4, so I preceded to try to update just the one. I used the Label, with escaped spaces (which also works with just quoted label btw "Command Line Tools for Xcode-13.4"

softwareupdate -i Command\ Line\ Tools\ for\ Xcode-13.4

In doing so, ALL 3 updates of Command Line Tools disappeared and I was able to continue.

Hope this helps someone else out there.

Lurleen answered 7/6, 2022 at 22:16 Comment(0)
P
2

I arrived here trying to install Appium. Adding my answer in case other folks land here for the same issue.

appium-doctor --ios

... bunch of stuff...

WARN AppiumDoctor ✖ Error running xcrun simctl

... bunch of stuff...

info AppiumDoctor ### Manual Fixes Needed ###

info AppiumDoctor The configuration cannot be automatically fixed, please do the following first:

WARN AppiumDoctor ➜ Manually install Xcode, and make sure 'xcode-select -p' command shows proper path like '/Applications/Xcode.app/Contents/Developer'

In my case

xcode-select -p

/Library/Developer/CommandLineTools

which appeared wrong...but I knew I had recently updated Xcode and the command line tools

so...

sudo xcode-select -r (sudo required)

then...

xcode-select -p
/Applications/Xcode.app/Contents/Developer

After this, no warning. Appium-doctor returned clean.

Perfectible answered 16/2, 2021 at 15:12 Comment(0)
H
1

Hello I solved it like this:

Install Application> Xcode.app> Contents> Resources> Packages> XcodeSystemResources.pkg.

Hunfredo answered 10/2, 2020 at 10:25 Comment(0)
L
0

xCode version 11.2.1 is necessary for building app in iPad 13.2.3, When I directly try to upgrade from xcode 11.1 to 11.2.1 through App Store it get struck, So after some research , I found a solution to upgrade by removing the existing xcode from the system

So here I am adding the steps to upgrade after uninstalling existing xcode.

  1. Go to Applications and identify Xcode and drag it to trash.
  2. Empty trash to permenently delete Xcode.
  3. Now go to ~/Library/Developer/ folder and remove the contents completely Use sudo rm -rf ~/Library/Developer/ to avoid any permission issue while deleting
  4. Lastly remove any cache directory associated with xcode in the path ~/Library/Caches/com.apple.dt.Xcode sudo rm -rf ~/Library/Caches/com.apple.dt.Xcode/*
  5. After completing the above steps you can easly install xcode from App Store, which will install the current latest version of xcode

Note: Please take a backup of your existing projects before making the above changes

Ldopa answered 9/12, 2019 at 14:39 Comment(0)
S
0

softwareupdate --install will work fine, avoid running rm -rf which may have unintended side effects.

Don't forget quotes or escape spaces with \!

softwareupdate --list # get available updates
softwareupdate --install "Command Line Tools for Xcode-xxx"
Satinet answered 31/1 at 14:44 Comment(0)
S
0

I noticed when you update your macOS version, the CLI does not necessarily recognize the latest version of your Xcode.

Try this command to reset your xcode-select version:

sudo xcode-select --reset

And then later on confirm your version by running the command below:

/usr/bin/xcodebuild -version
Scroop answered 1/2 at 2:48 Comment(0)
H
-1

Update with this one-liner.

softwareupdate --install -a
Haul answered 28/12, 2021 at 9:55 Comment(0)
B
-2

This reminds me why I hate MacOS. Every time I tried one of these errors I would get the incomprehensible error: No install could be requested (perhaps no UI is present) Turns out this "CLI" actually needs a graphical session to run. WTF! Very useful when you're actually only ever connecting to the remote mac server over SSH to queue iOS builds.

So the answer for me was:

Physically travel to the Mac, attach screen, mouse and keyboard, and run the command there.

Bubalo answered 6/2, 2023 at 8:6 Comment(0)
I
-3

To those having this issue after update to Catalina, just execute this command on your terminal

sudo rm -rf /Library/Developer/CommandLineTools; xcode-select --install;
Infringe answered 22/11, 2019 at 17:34 Comment(1)
This doesn’t add anything to the other answers that already mention these exact commands.Bluey

© 2022 - 2024 — McMap. All rights reserved.