Terminal Tips: Install software updates from the command line

If you want to do an automatic install of all the updates for your particular Mac, first log in as an administrative user. Then open Terminal.app (located in /Applications/Utilities), and type (or copy/paste) the following command:
sudo softwareupdate -i -a
and hit Return. Next, you'll be prompted to enter your password; do so, and then hit Return. The application will then look for available updates, download them, and then install them. You will see the progress in Terminal. If no updates are available, Terminal will let you know.
This command replicates the functionality of the normal Software Update utility. However, you can use it on other machines in the background via SSH remote login, or you could apply a specific update rather than the full list of available patches. To see all the command options, type
man softwareupdate at the Terminal prompt.Want more tips and tricks like this? Visit TUAW's Terminal Tips section!
Share
Categories
Sure, you could update your Apple software by opening Software Update from the Apple menu. But what if you're inclined to use a command...
Add a Comment
This + 'dsh' is a godsend on a cluster....
December 02 2008 at 11:54 PM Report abuse Permalink rate up rate down ReplyThere is a man page for softwareupdate. This describes additional options, such as selecting specific updates and ignoring others. With awk and a shell script, or perhaps an applescript, you could be very specific about which updates to install in the middle of the night when you're asleep.
December 02 2008 at 7:47 PM Report abuse Permalink rate up rate down ReplyNice! And it saved me from having to restart my computer (that just restarted this morning) just to update iTunes and Safari.
If you want to reboot after installing, just try the following:
sudo softwareupdate -i -a;reboot
I just updated 50 Macs with this command using Remote Desktop. Here is what you do.
Select your Macs in the list.
Click Unix
Enter in softwareupdate -i -a
Make the login user as root.
Then set back and relax. I have been waiting for this tip and it has just saved me hours as a system admin.
Thanks TUAW!!!
WillGonz
I believe there is also the advantage of not having to click through all the EULAs (if any) but I couldn't say for sure.
You can also use this via cron, to run your updates overnight, rather than randomly interrupting you during the day.
Just some reasons why.
Some updates will pop-up a license agreement, to prevent that set the shell environment variable "command_line_install" to 1, for example:
export command_line_install=1
before running the softwareupdate command. You can read about this in Apple's Command Line documentation for Tiger Server or Leopard Server.
You can avoid piping the administrator's password by adding the following line to /etc/sudoers (using visudo command):
Administrator ALL=PASSWD:ALL, NOPASSWD: /usr/sbin/softwareupdate, /sbin/reboot, /usr/bin/pmset
(assumes Administrator is the user that runs softwareupdate and reboot commands)
I've created a shell script "SUinstall" that handles all the tasks:
#!/bin/bash
export COMMAND_LINE_INSTALL=1
sudo /usr/sbin/softwareupdate -i -a
sudo /sbin/reboot
So I run "ssh adminstrator@remoteHost SUinstall" to install updates and reboot on the remote computer named "remoteHost"
StPaddy, this is one of the included template Unix commands in ARD (under Miscellaneous). You have the option to list updates that are available, just download them or download and install.
December 02 2008 at 12:10 PM Report abuse Permalink rate up rate down ReplyThe GUI version of Software Update couldn't sucessfully install the latest security update. I just tried the update from within Terminal as described above and the update installed sucessfully.
Thanks for the tip.
This is indeed a handy command--I just tried it using ARD and it works fine as long as you do the old trick of piping the root password into sudo.
The only bummer is that there doesn't seem to be a switch in the command for rebooting when it's complete.
Hot Apps on TUAW
Deals of the Day
more deals- miFrame Picture Frame Dock for iPad for $64 + $8 s&h
- Refurb Apple iPod nano 8GB MP3 Player for $99 + free shipping, 16GB for $119
- Bling Diamond Snap-On Shell Case for iPhone 4 / 4S for $2 + $2 s&h
- Hannspree Apple-Shaped 28" 1080p LCD HDTV for $270 + free shipping
- Philips wOOx Alarm Clock Radio for Apple iPod / iPhone for $60 + free shipping
- iWatchz Elemetal Collection Bracelet for iPod nano for $75 + free shipping
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



13 Comments