I am a Linux user and have never used OSX before. Someone asked me for help with installing some software on an OSX "Lion" server. I asked him to give me an SSH shell, assuming that would be sufficient. However things are more tricky than I thought.

I wanted to install homebrew, but it didn't install because there was no cc on the system. After some google, I suppose I need to install Xcode. I just downloaded xcode 4.5 from the apple developer site, and mounted it on the system. It contains a dir Xcode.app with a bunch of stuff in it. How do I go from here?

Can I install Xcode without physical access to the machine? All I really want is get homebrew running at this point.


8 Answers 8


You might be better off just installing the standalone Developer Command Line Tools (which includes gcc and other standard developer toolchain items). You can get it from Apple's Developer Downloads (which requires a free developer account). Unfortunately there's no direct link, but just search for command line tools and you'll find it (note that there are different downloads for Lion and Mountain Lion).

The download is a DMG. Mount that, and you'll find a .mpkg file, which you can install via the command line: sudo installer -pkg "Command Line Tools.mpkg" -target /.

  • +1 for keeping the bare package in mind. +3 for install from terminal - I'll edit my answer down a bit since Xcode is already downloaded, the tools are there in Xcode.app/Contents/Developer and could easily be copied to a convenient path for running.
    – bmike
    Dec 22, 2012 at 18:15
  • Yeah, I'm sure how/if the tools included in the Xcode package differ from the standalone download. Presumably somewhat different given that Xcode has the download tools option as well. In any event, if you're starting from scratch and want a "clean" install doing things from the command line only, this is probably the way to go.
    – robmathers
    Dec 22, 2012 at 18:20
  • 2
    I believe the last time I checked, the Xcode tools have extra headers and things for serving the GUI building and the Command Line tools are stripped down a bit / built separately with slightly different flags when compiled, but also generally the same version as major Xcode releases. In practice, I've never seen the differences get noticed let alone matter. AFAIK, Xcode pulls down the package you mentioned and installs it so you have both - the xcrun version of the toolset and the /usr/bin version of the toolset.
    – bmike
    Dec 22, 2012 at 18:24
  • Yay it worked. I just installed brew. There is a typo in your post, it should read sudo installer instead of sudo install. Dec 22, 2012 at 19:00
  • @Jeroen thanks for that, fixed. Not sure how I missed it.
    – robmathers
    Dec 22, 2012 at 22:28

I recently had to install Xcode command line tools on Mountain Lion over SSH. Here's how I did it.

  1. If you don't have a free Apple developer account, register for one

  2. Login to https://developer.apple.com/downloads

  3. Download the "Command Line Tools for Xcode" appropriate for your version of OSX

    For me, that was "Command Line Tools (OS X Mountain Lion) for Xcode - April 2014"

  4. Copy the dmg file to your remote

    In the following command, I'm using scp to securely copy the file from my local computer to the remote named remote

    $ scp ~/Downloads/command_line_tools_for_osx_mountain_lion_april_2014.dmg remote:Downloads/
  5. ssh to your remote

    $ ssh remote
  6. mount the dmg file on the remote

    Here, I'm using hdiutil to mount the image

    $ hdiutil attach ~/Downloads/command_line_tools_for_osx_mountain_lion_april_2014.dmg
  7. install the package contained in the dmg

    Here, installer must be run with sudo because this package needs to be installed on the root file system

    $ cd /Volumes/Command\ Line\ Tools\ \(Mountain\ Lion\)
    $ sudo installer -pkg Command\ Line\ Tools\ \(Mountain\ Lion\).mpkg -target /
  8. unmount the dmg file

    $ hdiutil detach /Volumes/Command\ Line\ Tools\ \(Mountain\ Lion\)
  9. delete the dmg file from the remote; optional

    I see no purpose keeping it around, but you can if you want.

    $ rm ~/Downloads/command_line_tools_for_osx_mountain_lion_april_2014.dmg

This is pretty old, but for anyone who comes by this, there is a simple, built-in, one-liner to install the Command Line Tools without the need to download any .dmg or .pkgs. This is available even on a fresh install of macOS.

The command is:

xcode-select --install

According to the man page:

Opens a user interface dialog to request automatic installation of the command line developer tools.

It seems to have been available since Xcode 3.0 was around (OS X 10.5).

  • 1
    I see no --install switch in xcode-select version 2311, man page from November 16, 2011, Mac OS X 10.8.5. May 18, 2017 at 16:17
  • Neither do I in xcode-select version 2349, man page from March 08, 2016.
    – user44400
    Feb 9, 2019 at 8:28
  • 1
    it's there in the output of xcode-select --help (version 2384)
    – airtonix
    Mar 24, 2021 at 0:45
# Install Command-line tools as dependency for Homebrew
xcode-select --install # Sets the development directory path to /Library/Developer/CommandLineTools

# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Mas (command-line interface for Mac App Store)
brew install mas

# Search for Xcode showing only the first 5 results
mas search xcode | head -5
# Install Xcode using App ID
mas install 497799835 # The appid for Xcode shown when doing search

sudo xcode-select -r  # Reset the development directory path to put to Xcode /Applications/Xcode.app/Contents/Developer

#sudo xcodebuild -license

# Updaate all Apple software and auto agree to any licenses and restart if necessary
sudo softwareupdate --install --agree-to-license -aR
  • How does this answer the question asked on top?
    – nohillside
    Jan 26, 2021 at 20:28
  • Oh. This almost worked... I got Redownload Unavailable with This Apple ID Mar 1, 2021 at 21:47
  • @Richard Lalancette did you already have Xcode installed? Do you know what caused the error? Mar 2, 2021 at 5:03
  • Didn't have it installed. I think the laptop security forced me to download manually from apple.developer.com Mar 3, 2021 at 13:29
  • Pretty cool way to install regardless! Mar 3, 2021 at 13:30

2018 answer: There is xcode-install vom KrauseFX https://github.com/KrauseFx/xcode-install


I found out that Homebrew install the Xcode Command Line Tools as well.

The big benefit is for me that I can do it from a terminal (even ssh) and the installer do not show a UI-Pop-Window, which blocks me from use with remote terminal.

Tested with Homebrew version 2.1.10 (git revision b7d38f; last commit 2019-08-12).

For me that steps was much easier, then downloading dmg package from apple and copy it by ssh to the target machine.

The installer command will generate (copied from the website)

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

the following output:

==> This script will install:
==> The following new directories will be created:
==> The Xcode Command Line Tools will be installed.


Downloading Command Line Tools (macOS Mojave version 10.14) for Xcode
Downloaded Command Line Tools (macOS Mojave version 10.14) for Xcode
Installing Command Line Tools (macOS Mojave version 10.14) for Xcode
Done with Command Line Tools (macOS Mojave version 10.14) for Xcode
  • Actually, did command did not download the CLI tools... Mar 1, 2021 at 21:45

The tools you need are all in Xcode.app/Contents/Developer and if you have that folder, you are done installing since OS X applications can run from anywhere.

If you want to use Xcode, just click on the icon or open -a the path to the folder Xcode.app and you will launch the app. Most people move the Xcode.app folder into /Applications (or ~/Applications) to "install it"

Oh - when you fire up Xcode you will want to open the preferences, go to the Downloads pane and install the stand alone command line tools. This places the compilation toolchain in /usr/bin so you don't have to use xcrun --find gcc and xcrun --find make to locate the path to the tools relative to wherever you dropped the Xcode.app folder.

  • Nevertheless Command Line Utilities are also needed to get homebrew to work. It's probably easiest to ask the owner of the OS X system to install the stuff for you (or connect via VNC and do it yourself)
    – nohillside
    Dec 22, 2012 at 18:12


tell application "Finder" to open ("Macintosh HD")
tell application "Finder"
    set target of Finder window 1 to folder "Downloads" of folder "vagrant" of folder "Users" of startup disk
    open document file "{{ osx_xcode_file }}" of folder "Downloads" of folder "vagrant" of folder "Users" of startup disk
end tell

Replace Xcode "{{ osx_xcode_file }}" with the version/filename you have downloaded.

Install XCODE

tell application "Finder"
    activate "Xcode"
    with timeout of 1000000 seconds
        copy file "Xcode:Xcode.app" to folder "Macintosh HD:Applications"
    end timeout
end tell

Optionally Delete a previous XCODE

rm /Applications/Xcode.app causes unforsean issues

tell application "Finder"
    activate "Applications"
    considering case
        with timeout of 1000000 seconds
            set sourceFolder to POSIX file "/Applications/Xcode.app"
                delete sourceFolder
            on error errorMessage number errorNumber
                set _error to errorMessage
                set _errorNum to errorNumber
            end try
        end timeout
    end considering
end tell

Save each file as an scriptname.scpt

run: /usr/bin/osascript scriptname.scpt Run as a console user (NOT ROOT)

  • How can you run this via ssh? Also how is this better than the command line only developer tools?
    – mmmmmm
    Feb 2, 2016 at 17:54
  • Hi Mark, we have a specific requirement to have the full xcode install in place. ssh user@hostname "onascript <path/to/file>/myscript.scpt
    – casibbald
    Feb 15, 2016 at 18:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .