Tuesday, December 16, 2008

Updating Apple software from the command line

Macs check for system updates on their own (by default) and prompt you when there are updates to apply to your system. If you want to update immediately, like after a fresh OS X install, you can check for updates by clicking on the Apple menu icon, then Software Update. However, if you want to update a system remotely -- a frequent need for remote servers -- you can do it from the command line.

The softwareupdate command

Use the softwareupdate (all one word) command to check for updates or install them. Here are some commonly used switches:

Switch Effect
--list list available updates
--install install all available updates
--install packagename install only packagename
--schedule on turn automatic checking on
--schedule off turn automatic checking off

If you check for new software and there is nothing to apply, you get output like this:

iBook-G4:~ keithw$ softwareupdate --list
Software Update Tool
Copyright 2002-2007 Apple

No new software available.

When updates are available, you get output like this:

iBook-G4:~ keithw$ softwareupdate --list
Software Update found the following new or updated software:
* iLifeSupport82-8.2
iLife Support (8.2), 2770K [recommended]
* QuickTime-7.4.1
QuickTime (7.4.1), 59940K [recommended] [restart]
* MacOSXUpd10.5.2-10.5.2
Mac OS X Update (10.5.2), 349324K [recommended] [restart]

To install updates, use the --install --all option:

iBook-G4:~ root# softwareupdate --install --all
Software Update Tool
Copyright 2002-2007 Apple

Downloading iLife Support 0..20..40..60..80..100
Verifying iLife Support
waiting iLife Support
waiting QuickTime
Downloading Mac OS X Update 0..20..40..60..80..100
Verifying Mac OS X Update
waiting Mac OS X Update
Installing iLife Support 0..20..40..60..80..100
Done iLife Support
Installing QuickTime 0..20..40..60..80..100
Done QuickTime
Installing Mac OS X Update 0..20..40..60..80..100
Done Mac OS X Update
Done.

You have installed one or more updates that requires that you restart your
computer. Please restart immediately.