'Xcode - Install additional required components using command line

I recently got a used Mac with Mountain Lion on it. I don't know of the admin password or anything, but I do know how to run a command line.

So here's what I am stuck on: asdf

When I click install, it asks me for my username and password (which I don't know).

I want to install this via single-user mode (Cmd+S on Startup), which I accepted the license using it.

Do you guys know how I could achieve this?



Solution 1:[1]

At least on Xcode 9.2, you could use:

sudo xcodebuild -runFirstLaunch

to accept the agreement and install additional components.

Solution 2:[2]

Resolved this issue using the below commands, it is on OS El Capitan and Xcode beta 7.2

sudo /Applications/Xcode-beta.app/Contents/Developer/usr/bin/xcodebuild  -license accept
sudo installer -pkg /Applications/Xcode-beta.app/Contents/Resources/Packages/MobileDevice.pkg -target /
sudo installer -pkg /Applications/Xcode-beta.app/Contents/Resources/Packages/MobileDeviceDevelopment.pkg -target /

Change the Xcode-beta.app path to your own, and you would need sudo(admin) access. Close your Xcode and open again.

Solution 3:[3]

I know this is a looooooong time after the original post, but just in case anyone else finds this (as I did) while trying to install Xcode 8.2.1 on El Capitan (10.11.6)…

I had all the same problems listed here – long delay for launch, then asking for additional tools to be installed, only to fail. The command line tools install also failed. I tried the various command line solutions listed, but none worked.

However, upon checking the log I saw that I was getting errors with certificates. On a hunch, I decided to put the system clock back to 20 December 2016 - voila, installs work like magic.

Put the clock back to today (30 October 2019) and still seems to work.

Solution 4:[4]

The commandline way to install required components is:

/Applications/Xcode.app/Contents/MacOS/Xcode -installComponents

Solution 5:[5]

Here's what I ended up doing. I went into recovery mode (CMD+R on startup), then to Terminal. I typed in

resetpassword

which then brought up a dialog of where I can select the user and set the password.

I then set the root password. Now when I can enter an admin password, I type in "root" and the password I set.

I got Xcode to load finally!

Solution 6:[6]

Xcode 5.1.1 have a new argument:

> xcode -installComponents

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shim
Solution 2 Heath Borders
Solution 3
Solution 4 Ivo Jansch
Solution 5 x86cam
Solution 6 k06a