Skip to content

Instantly share code, notes, and snippets.

@nekator
Last active August 25, 2023 14:24
Show Gist options
  • Save nekator/fdf046b834e3221555db252e5120b622 to your computer and use it in GitHub Desktop.
Save nekator/fdf046b834e3221555db252e5120b622 to your computer and use it in GitHub Desktop.
install Xcode from terminal

1. Download Xcode from https://developer.apple.com/download/more/ (this requeires to Login in with an Apple Developer Account)

At the moment id don´t know how to authenticate so i have no clue to download the xip via curl/wget.
In my case i downloaded the file and copied it via scp to my mac.

eg. for Xcode 9.2 https://developer.apple.com/services-account/download?path=/Developer_Tools/Xcode_9.2/Xcode_9.2.xip

2. Verify Signature of xip file

pkgutil --verbose --check-signature path/to/xip

eg. pkgutil --verbose --check-signature Xcode_9.2.xip

3. Extract the PBZX stream from the archive

xar -xf path/to/xip

eg. xar -xf Xcode_9.2.xip

4. Obtain a PBZX v2 unpacker and... unpack the packed stuff.

curl -O https://gist.githubusercontent.com/pudquick/ff412bcb29c9c1fa4b8d/raw/24b25538ea8df8d0634a2a6189aa581ccc6a5b4b/parse_pbzx2.py
python parse_pbzx2.py Content

5. Decompress the archive

Locate all Concent.partXX.cpio.xz file with more than 0Bytes and decompress them

xz -d Content.partXX.cpio.xz

6. Concat decompressed cpio files

for i in *.cpio; do cat $i >> Content.cpio; done

7. Unpack cpio

sudo cpio -idm < Content.cpio

8. Move Xcode to /Applications

sudo mv ./Xcode.app /Applications/
@iSemary
Copy link

iSemary commented Jul 21, 2019

I just came here to thank you so much !!
You're awesome, I've been trying to install xcode on my mac and always failed for more than week, but after trying your commands xcode worked! So thank you again !
Xcode 8 on MacOs High sierra 10.13.6

@ykhandelwal913
Copy link

For the above process, user need to make sure he has enough space( at least twice to the xcode size) as we are extracting the Content and packaging it back.

@nekator
Copy link
Author

nekator commented May 27, 2020

@YogiKhan you are absolutely 💯 correct.

BTW I would like to mention https://docs.fastlane.tools/actions/xcode_install/ for headless installation of XCode which is my preferred method right now.

@mtrimarchi
Copy link

On step 6 simply use for i in *.cpio; do cat $i >> Content.cpio; done

@nekator
Copy link
Author

nekator commented Oct 27, 2020

On step 6 simply use for i in *.cpio; do cat $i >> Content.cpio; done

Thanks for this great addition. Changed it in the gist 👍

@pechisworks
Copy link

THIS was the only working solution for me.
The system volume of my mac mini has less than 30gb free space, so no app store install would work.
On my second HDD I've got plenty of free space, but the Archive Utility always bloads my system volume until Mac Os crashed.

@nekator
Copy link
Author

nekator commented Jan 26, 2021

https://gist.github.com/dcondrey/fec86d6ecedaf37c622cc4d9ba5c5413

This is a pretty elegant way using mas.
👍

@ClebsonDantasUchoa
Copy link

Thank you very much, it worked perfectly !!

@Seminioni
Copy link

Seminioni commented Aug 30, 2021

Got an error on pre-last step. I tried to unpack XCode 12.5.1. At step 5 I replaced command xz -d Content.partXX.cpio.xz to catch all .cpio file with -> xz -d Content.part*.cpio.xz. Is it true? @nekator
image

@johndpope
Copy link

johndpope commented Aug 31, 2021

Use this - https://github.com/xcpretty/xcode-install

gem install xcode-install
xcversion list
// grab the latest

xcversion update

@ugurerkan
Copy link

ugurerkan commented Oct 16, 2021

@nekator for step 5 Locate all Concent.partXX.cpio.xz file with more than 0Bytes and decompress them I think this find command could be useful, thank you for the instructions btw 🤩

find . -type f -name 'Content.part*.cpio.xz' -size +0 -exec xz -d {} \;

@Gerst20051
Copy link

I've created the following script to get the download urls for the selected Xcode versions.

alias xcode.download.link='curl -s https://xcodereleases.com/data.json | jq -r '\''.[] | (.name + ": " + .version.number + " (" + .version.build + ") " + (.version.release | to_entries[] | "\(.key) \(.value)"))'\'' | fzf -m --no-sort | awk -F'\''[()]'\'' '\''{print $2}'\'' | while read build; do { curl -s https://xcodereleases.com/data.json | jq -r ".[] | select(.version.build | contains(\"${build}\")) | .links.download.url" } done'

Screen Shot 2022-08-07 at 1 37 00 AM

@farshadmb
Copy link

After a little search, I end up with a convenient solution.

Step 4.

brew install pbxz

Step 5.

pbxz -n Content | tar -x -v

Step 6.

Copy the Xcode.app and Enjoy it 😄

@Gerst20051
Copy link

What is pbxz? Do you have any links?

@farshadmb
Copy link

farshadmb commented Jan 3, 2023

@Gerst20051 install it via Homebrew brew install pbxz

@farshadmb
Copy link

What is pbxz? Do you have any links?

Jonathan Levin pbzx to properly unpack pbzx chunks and pipe the output to tar

@Gerst20051
Copy link

Is that in a tap? I don't see it on homebrew.

https://formulae.brew.sh/formula/pbxz
https://formulae.brew.sh/cask/pbxz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment