Filed under: Terminal Tips
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!

![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 1 of 1)
waiownsyou said 11:29AM on 12-02-2008
I don't understand why anyone would learn to explicitly use this. Sure there's the whole SSH thing but come on, I'm sure you can go up to a computer and do it at a later time instead of running a command downstairs.
Reply
brian said 4:19PM on 12-02-2008
Well, maybe you've got SSH enabled on your Mac at home, and a slow connection, so if you learn (from TUAW, perhaps) that new updates are available, you can SSH home, run the command, and have your updated computer ready and waiting for you when you get home.
Of course, I *never* run updates until they've been out for a week or so, so as handy as this is I'll never use it. :-)
StPaddy said 11:32AM on 12-02-2008
In a lab setting, sending this command using Apple Remote Desktop is going to save me a ton of time. Thanks.
Reply
JKT said 11:41AM on 12-02-2008
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.
Reply
Chuck said 11:59AM on 12-02-2008
The 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.
Reply
acletras said 12:11PM on 12-02-2008
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.
Reply
bbarrera said 12:16PM on 12-02-2008
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"
Reply
TjL said 12:18PM on 12-02-2008
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.
Reply
Doug said 2:02PM on 12-02-2008
If you want to reboot after installing, just try the following:
sudo softwareupdate -i -a;reboot
Reply
raff said 3:02PM on 12-02-2008
Nice! And it saved me from having to restart my computer (that just restarted this morning) just to update iTunes and Safari.
Reply
WillGonz said 4:16PM on 12-02-2008
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
Reply
WPT said 8:06PM on 12-02-2008
There 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.
Reply
Dr. ScottyB said 11:57PM on 12-02-2008
This + 'dsh' is a godsend on a cluster....
Reply