<!-- 
The contents of this Documentation are subject to the Public Documentation
License Version 1.01 (the "License"); you may only use this Documentation if
you comply with the terms of this License. A copy of the License is
available at http://www.opensolaris.org/os/community/documentation/license.
-->

<chapter id="ips_cmds"><title>Working With Packages</title><highlights><para>IPS provides a set of commands to install and manage packages on your
system.</para><orderedlist><listitem><para><olink type="auto-generated" targetptr="gihhp" remap="internal"></olink></para>
</listitem><listitem><para><olink type="auto-generated" targetptr="gihej" remap="internal"></olink></para>
</listitem><listitem><para><olink type="auto-generated" targetptr="gihfn" remap="internal"></olink></para>
</listitem><listitem><para><olink type="auto-generated" targetptr="gijkt" remap="internal"></olink></para>
</listitem><listitem><para><olink type="auto-generated" targetptr="gijmp" remap="internal"></olink></para>
</listitem><listitem><para><olink type="auto-generated" targetptr="gijmk" remap="internal"></olink></para>
</listitem><listitem><para><olink type="auto-generated" targetptr="gijmo" remap="internal"></olink></para>
</listitem><listitem><para><olink type="auto-generated" targetptr="gijjo" remap="internal"></olink></para>
</listitem><listitem><para><olink type="auto-generated" targetptr="gijkn" remap="internal"></olink></para>
</listitem><listitem><para><olink type="auto-generated" targetptr="gikvp" remap="internal"></olink></para>
</listitem><listitem><para><olink type="auto-generated" targetptr="gijku" remap="internal"></olink></para>
</listitem><listitem><para><olink type="auto-generated" targetptr="gijjx" remap="internal"></olink></para>
</listitem><listitem><para><olink type="auto-generated" targetptr="gijkz" remap="internal"></olink></para>
</listitem>
</orderedlist><para>See also <olink type="auto-generated" targetptr="cmd_ref" remap="internal"></olink> and
the <ulink url="http://" type="text">pkg(1) man page</ulink> sections for
a complete list of options associated with the <command>pkg(1)</command> command.</para>
</highlights><sect1><title>Installing and Managing Packages</title><para>The Image Packaging System enables users to connect to a repository
and download and install software applications. These software applications
are available as packages in a repository. The default repository for the
OpenSolaris 2009.06 system is <ulink url="http://pkg.opensolaris.org" type="url"></ulink>.</para><task id="gihhp"><title>How to Install or Update a Package</title><taskprerequisites><para>When installing or updating packages, the packages are first searched
for in the preferred publisher's repository catalog. If the packages are not
found in the preferred publisher's catalog, then the catalogs of the remaining
publishers are searched.</para><para>The preferred publisher for an OpenSolaris 2009.06 system is <filename>opensolaris.org</filename>, and the packages are retrieved from the <filename>http://pkg.opensolaris.org/release</filename> repository.</para><para>To change the preferred publisher, see <olink type="auto-generated" targetptr="gijmo" remap="internal"></olink>.</para>
</taskprerequisites><procedure remap="single-step"><step><para>Use the following command to install or update a package.</para><para><command>$ pfexec pkg install [-vq] <replaceable>pkg_fmri</replaceable></command></para><note><para>The <command>pkg install</command> command will automatically
retrieve the newest package information available from the configured publishers
for an image when necessary. The <command>pkg install</command> command can
also be used to upgrade one or more packages, and will automatically upgrade
package dependencies when necessary.</para>
</note>
</step>
</procedure><example><title>Install a Package</title><para>This example installs the <literal>SUNWphp524-mysql</literal> package.
The output displays the status of the download, number of packages that were
installed, number of files that were installed and the size (in megabytes)
of the download.</para><screen>$ pfexec pkg install SUNWphp524-mysql
DOWNLOAD                PKGS       FILES     XFER (MB)
Completed     			    4/4     362/362   86.93/86.93

PHASE                   ACTIONS
Install Phase           493/493
PHASE                    ITEMS
Reading Existing Index   7/7</screen>
</example><example><title>Install a Package From a Specific Publisher</title><para>When an image is created, a preferred publisher is set and this is the
default publisher from which packages are downloaded and installed. </para><para>This example installs the <literal>SUNWphp524-mysql</literal> package
from the <literal>example.opensolaris.org</literal> publisher.</para><screen>$ pfexec pkg install pkg://example.opensolaris.org/SUNWphp524-mysql</screen>
</example><taskrelated-custom><title>Dry-Run Installation</title><para>Before installing packages, you have the option to perform a dry&mdash;run
installation. A dry run enables you to execute the command without making
persistent changes to the image. The dry&mdash;run option does not install
any packages and only shows the changes that are made if the packages are
installed. For details on how to perform a dry-run installation, see <olink type="auto-generated" targetptr="gihej" remap="internal"></olink>.</para>
</taskrelated-custom>
</task><task id="gihej"><title>How to Perform a Dry-Run Installation Inside a New
Image</title><procedure remap="single-step"><step><para>Use the following command to execute a dry-run installation.</para><para><command>$ pfexec pkg install <option>n</option> [-v] <replaceable>pkg_fmri</replaceable></command></para><note><para><replaceable>pkg_fmri</replaceable> refers to a package name along
with a version number and a sub-version number, if applicable. See the <olink type="auto-generated" targetptr="fmri" remap="internal"></olink> section for more information
about fmris.</para>
</note>
</step>
</procedure><example><title>Performing a Dry-Run Installation of the <literal>amp</literal> Package</title><para>The following example shows a dry-run installation of the <replaceable>amp</replaceable> package
with verbose (<option>v</option>) output.</para><screen><command>$ pfexec pkg install <option>nv</option> <replaceable>amp</replaceable></command></screen><screen>$ pfexec pkg install -nv amp
Creating Plan | Before evaluation:
UNEVALUATED:
+pkg:/amp@0.5.11,5.11-0.110:20090320T185834Z

After evaluation:
None -&gt; pkg:/amp@0.5.11,5.11-0.110:20090320T185834Z
None -&gt; pkg:/SUNWphp52@5.2.9,5.11-0.110:20090320T183517Z
None -&gt; pkg:/SUNWlibmcrypt@2.5.8,5.11-0.110:20090320T182401Z
None -&gt; pkg:/SUNWtidy@1.0.0,5.11-0.110:20090320T184937Z
None -&gt; pkg:/SUNWgnu-idn@0.6.8,5.11-0.110:20090320T181123Z
None -&gt; pkg:/SUNWcurl@7.19.0,5.11-0.110:20090320T174003Z
None -&gt; pkg:/SUNWapch22@2.2.11,5.11-0.110:20090320T173257Z
None -&gt; pkg:/SUNWapr13@1.3.3,5.11-0.110:20090320T173337Z
None -&gt; pkg:/SUNWapu13@1.3.4,5.11-0.110:20090320T173342Z
None -&gt; pkg:/SUNWapch22m-dtrace@0.3.1,5.11-0.110:20090320T173316Z
None -&gt; pkg:/SUNWapch22m-fcgid@2.2,5.11-0.110:20090320T173320Z
None -&gt; pkg:/SUNWapch22m-php52@5.2.9,5.11-0.110:20090320T173324Z
None -&gt; pkg:/SUNWapch22m-security@2.5.7,5.11-0.110:20090320T173330Z
Actuators:
      restart_fmri: svc:/system/manifest-import:default</screen>
</example>
</task><task id="gihfn"><title>How to Search for Packages</title><procedure remap="single-step"><step><para>Use the following command to search for packages based on the
various properties indexed by the packaging system. The <replaceable>server</replaceable> represents
the <literal>origin_uri</literal> of a repository.</para><para><command>$
pkg search [-alprI] [-s <replaceable>server</replaceable>] <replaceable>query</replaceable></command></para><para>By default, the search command searches for the package in the repository
or repositories associated with the current image. Use the <option>l</option> option
to search only the installed packages for the current image. </para><para>By default, the search results list the matching actions contained within
a package's manifest. Use the <option>p</option> option to display the results
as a list of unique packages instead.</para>
</step>
</procedure><example><title>Search for a Package in the Installed Image</title><para>The following example searches for the <literal>SUNWbash</literal> package
in the installed image.</para><screen>$ pkg search -l SUNWbash
INDEX      ACTION    VALUE        PACKAGE
fmri       set       fmri         pkg:/SUNWbash@3.2.25-0.110
legacy_pkg legacy    SUNWbash     pkg:/SUNWbash@3.2.25-0.110</screen>
</example><example><title>Search for a Package in a Remote Repository</title><para>The following example searches for the <filename>amp</filename> package
in the remote (<option>r</option>) repository associated with the <emphasis role="strong">current</emphasis> image.</para><screen>$ pkg search -r amp
INDEX      ACTION    VALUE     PACKAGE
description set       AMP    pkg:/amp@0.5.11-0.86
description set       AMP    pkg:/amp-dev@0.5.11-0.86
description set       AMP    pkg:/amp-dev@0.5.11-0.101
description set       AMP    pkg:/amp-dev@0.5.11-0.86
description set       AMP    pkg:/amp-dev@0.5.11-0.86
description set       AMP    pkg:/amp-dev@0.5.11-0.86
description set       AMP    pkg:/amp@0.5.11-0.86
description set       AMP    pkg:/amp@0.5.11-0.101
description set       AMP    pkg:/amp-dev@0.5.11-0.86</screen>
</example><example id="gimix"><title>Search for a Package by Description</title><para>The following example searches for a <replaceable>book</replaceable> package.
Generally, the complete metadata of the package, such as attribute values,
path names, file names, descriptions and so on are searched. Hence, the search
results will display a list of all packages that contain the search term in
path, file name, description, and so on.</para><screen remap="wide">$ pkg search book
INDEX      ACTION    VALUE                                 PACKAGE
basename   dir       usr/share/doc/gtkmm-2.4/examples/book pkg:/SUNWgtkmm@0.5.11-0.93
basename   dir       usr/share/doc/gtkmm-2.4/examples/book pkg:/SUNWgtkmm@0.5.11-0.86
basename   dir       usr/share/doc/gtkmm-2.4/examples/book pkg:/SUNWgtkmm@0.5.11-0.90
basename   dir       usr/share/doc/gtkmm-2.4/examples/book pkg:/SUNWgtkmm@0.5.11-0.95
basename   dir       usr/share/doc/gtkmm-2.4/examples/book pkg:/SUNWgtkmm@0.5.11-0.86
basename   dir       usr/share/doc/gtkmm-2.4/examples/book pkg:/SUNWgtkmm@0.5.11-0.98
basename   dir       usr/share/doc/gtkmm-2.4/examples/book pkg:/SUNWgtkmm@0.5.11-0.97
basename   dir       usr/share/doc/gtkmm-2.4/examples/book pkg:/SUNWgtkmm@0.5.11-0.89
basename   dir       usr/share/doc/gtkmm-2.4/examples/book pkg:/SUNWgtkmm@0.5.11-0.94
basename   dir       usr/share/doc/gtkmm-2.4/examples/book pkg:/SUNWgtkmm@0.5.11-0.96
basename   dir       usr/share/doc/gtkmm-2.4/examples/book pkg:/SUNWgtkmm@0.5.11-0.91
description set       book                                 pkg:/SUNWdiveintopython@0.5.11-0.110
~</screen>
</example>
</task><task id="gijkt"><title>How to List the Contents of a Package</title><procedure remap="single-step"><step><para>Use the following command to list the action attributes of a package.</para><para><command>$ pkg contents [-Hmr] [-o <replaceable>attribute</replaceable>]
[-s <replaceable>sort_key</replaceable>] [-t <replaceable>action_type</replaceable>] <replaceable>pkg_fmri</replaceable></command></para>
</step>
</procedure><example><title>Listing the Contents of a Package</title><para>This example lists the name, mode of the file, size, path and the target
of the following actions in the <literal>SUNWzfs</literal> package:</para><itemizedlist><listitem><para><literal>dir</literal></para>
</listitem><listitem><para><literal>file</literal></para>
</listitem><listitem><para><literal>link</literal></para>
</listitem><listitem><para><literal>hardlink</literal></para>
</listitem>
</itemizedlist><para>If the package is not installed, use the <option>r</option> option to
retrieve the contents of the package from the server.</para><screen>$ pkg contents -t dir,file,link,hardlink -o action.name,mode,pkg.size,path,target zfs</screen><screen>NAME  MODE   SIZE PATH                      TARGET
dir   0755        etc
dir   0755        etc/fs
dir   0755        etc/fs/zfs
link              etc/fs/zfs/mount          ../../../sbin/zfs
link              etc/fs/zfs/umount         ../../../sbin/zfs
dir   0755        etc/zfs
dir   0755        lib
dir   0755        lib/amd64
link              lib/amd64/libzfs.so        libzfs.so.1
file  0755 469616 lib/amd64/libzfs.so.1
file  0644  62057 lib/amd64/llib-lzfs.ln
link              lib/libzfs.so              libzfs.so.1
     [ ... ]</screen>
</example>
</task><task id="gijmp"><title>How to Display Information About a Package</title><procedure remap="single-step"><step><para>Use the following command to display information about a package.
If no <replaceable>pkg_fmri</replaceable> is specified, information about
all installed packages is displayed.</para><screen><command>$ pkg info [-lr] [--license] <replaceable>pkg_fmri</replaceable></command></screen>
</step>
</procedure><example><title>Display Package Information</title><para>This example displays information about the <literal>amp</literal> package.
This example uses the <option>r</option> option to retrieve the data from
the servers if the package is not installed.</para><screen>$ pkg info -r amp
          Name: amp
       Summary: Cluster containing an AMP (Apache, MySQL, PHP) deployment kit
      Category: Web Services/Application and Web Servers
         State: Not installed
     Publisher: OpenSolaris
       Version: 0.5.11
 Build Release: 5.11
        Branch: 0.110
Packaging Date: Fri Mar 20 18:58:34 2009
          Size: 0.00 B
          FMRI: pkg:/amp@0.5.11,5.11-0.110:20090320T185834Z</screen>
</example><example><title>Display Copyright and License Information About a Package</title><para>This example displays the copyright and license information about the <filename>SUNWGlib</filename> package. This example uses the <option>r</option> option
to retrieve the data from the servers if the package is not installed.</para><screen>$ pkg info --license -r SUNWGlib
Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public
 License as published by the Free Software Foundation; either
 version 2 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Library General Public License for more details.

 You should have received a copy of the GNU Library General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

 Modified by the GLib Team and others 1997-1999.  See the AUTHORS
 file for a list of people on the GLib Team.  See the ChangeLog
 files for a list of changes.  These files are distributed with
 GLib at ftp://ftp.gtk.org/pub/gtk/. </screen>
</example>
</task><task id="gilmv"><title>How to Display Package State and Version Information</title><procedure remap="single-step"><step><para>Use the following command to uninstall existing packages.</para><para><command>$ pfexec pkg list [-aHsuvf] <replaceable>pkg_fmri</replaceable></command></para>
</step>
</procedure><example id="gilqu"><title>Display the most recent version information of all known versions of
a package.</title><para>This example uses the <option>a</option> option to retrieve the information
about all known versions of the package, whether installed or not.</para><screen>$ pkg list -a amp
NAME (PUBLISHER)         VERSION         STATE      UFIX
amp                      0.5.11-0.110    known      ----
amp (osrelease)          0.5.11-0.101    known      u---</screen>
</example>
</task><task id="gijmk"><title>How to Uninstall Packages</title><procedure remap="single-step"><step><para>Use the following command to uninstall existing packages.</para><para><command>$ pfexec pkg uninstall [-nvr] <replaceable>pkg_fmri</replaceable></command></para>
</step>
</procedure><example><title>Uninstalling a Package</title><para>This example uninstalls the <literal>SUNWphp524-mysql</literal>package.</para><screen><command>$ pfexec pkg uninstall SUNWphp524-mysql</command></screen><screen>PHASE        ACTIONS
Removal Phase  39/39 </screen>
</example>
</task><task id="gijkn"><title>How to Display Publisher Information</title><procedure remap="single-step"><step><para>Type the following command to display information about a publisher.
If no arguments are specified, the associated repositories, the repository's
associated origins and any available mirrors are displayed along with the
name of the publisher.</para><para><command>$ pkg publisher [-H] <replaceable>publisher</replaceable></command></para>
</step>
</procedure><example><title>Displaying Publisher Information</title><screen>$ pkg publisher
publisher                   TYPE    STATUS   URL
opensolaris.org (preferred) origin  online   http://pkg.opensolaris.org/release</screen>
</example>
</task><task id="gijmo"><title>How to Add or Update a Publisher</title><procedure remap="single-step"><step><para>Type the following command to update an existing publisher or
add an additional package publisher.</para><para><command>$ pfexec pkg set-publisher
[-P] [-k <replaceable>ssl_key</replaceable>] [-c <replaceable>ssl_cert</replaceable>]
[-O <replaceable>origin_url</replaceable>] <replaceable>publisher</replaceable></command></para><note><para>Command-line options are case-sensitive. Specify <option>O</option> and <option>P</option> in uppercase.</para>
</note>
</step>
</procedure><example><title>Adding an Additional Package Publisher</title><screen>$ pfexec pkg set-publisher -O  http://pkg.opensolaris.org/release osrelease</screen><screen>$ pkg publisher
PUBLISHER                     TYPE     STATUS   URI
OpenSolaris      (preferred)  origin   online   http://pkg.opensolaris.org/dev/
osrelease                     origin   online   http://pkg.opensolaris.org/release/</screen>
</example><example><title>Setting a Preferred Publisher</title><para>Use the <option>P</option> option along with the <option>O</option> option
to set a publisher as the preferred publisher. The preferred publisher's repository
will be searched first when performing package operations such as install
or upgrade.</para><screen>$ pfexec pkg set-publisher -P -O http://pkg.sunfreeware.com sunfreeware.com</screen><screen>$ pkg publisher
PUBLISHER                     TYPE     STATUS   URI
OpenSolaris                   origin   online   http://pkg.opensolaris.org/dev/
osrelease                     origin   online   http://pkg.opensolaris.org/release/
sunfreeware.com (preferred)   origin   online   http://pkg.sunfreeware.com</screen>
</example><taskrelated-custom><title>Naming of Publishers</title><para>A publisher is an identifier for a person, groups of persons, or a corporation
that publishes a package.</para><para>A publisher name can be any one of the following types:</para><itemizedlist><listitem><para>A host-like string such as <literal>opensolaris.org</literal>, <literal>sunfreeware.org</literal> and so on</para>
</listitem><listitem><para>A forward domain name such as <literal>extra.opensolaris.org</literal></para>
</listitem><listitem><para>A reverse domain name such as <literal>org.opensolaris.extra</literal></para>
</listitem><listitem><para>An identifier such as <literal>opensolarisextra</literal></para>
</listitem>
</itemizedlist>
</taskrelated-custom><taskrelated role="see-also"><para>The <command>pkg set-publisher</command> command is also used to add
and remove mirror repositories. For more information, see <olink type="auto-generated" targetptr="repo_mirror" remap="internal"></olink>.</para>
</taskrelated>
</task><task id="gijjo"><title>How to Remove Publisher Configuration </title><procedure><step><para>(Optional) A publisher cannot be removed if it is set to be the
preferred publisher. Set a different publisher to be the preferred publisher
before removing the publisher.</para><para><command>$ pfexec pkg set-publisher
-P -O <replaceable>repository</replaceable> <replaceable>publisher</replaceable></command></para>
</step><step><para>Type the following command to remove the configuration information
associated with a given publisher.</para><para><command>$ pfexec pkg unset-publisher <replaceable>publisher</replaceable></command></para><para></para>
</step>
</procedure><example><title>Removing a Preferred Publisher</title><para>In this example, the preferred publisher is first changed from <literal>sunfreeware.com</literal> to <literal>opensolaris.org</literal> using the <command>set-publisher</command> command. Then the <literal>sunfreeware.com</literal> publisher
is removed.</para><screen>$ pkg publisher
PUBLISHER                     TYPE     STATUS   URI
OpenSolaris                   origin   online   http://pkg.opensolaris.org/dev/
osrelease                     origin   online   http://pkg.opensolaris.org/release/
sunfreeware.com (preferred)   origin   online   http://pkg.sunfreeware.com</screen><screen>$ pfexec pkg set-publisher -P -O http://pkg.opensolaris.org/release opensolaris.org</screen><screen>$ pfexec pkg unset-publisher sunfreeware.com</screen><screen>$ pkg publisher
publisher                    TYPE    STATUS URL
opensolaris.org (preferred)  origin  online http://pkg.opensolaris.org/release</screen>
</example>
</task><task id="gikvp"><title>How to Update a Package</title><procedure remap="single-step"><step><para>If a newer version of an installed package is available in the
repository, install the package to obtain the latest available version.</para><para><command>$ pfexec pkg install <replaceable>package_fmri</replaceable></command></para>
</step>
</procedure>
</task><task id="gijku"><title>How to View the Operation History</title><procedure remap="single-step"><step><para>Type the following command to view the operation history of the
current image.</para><para><command>$ pkg history [-Hl]</command></para>
</step>
</procedure><example id="gijmc"><title>View Detailed Command History</title><screen>$ pkg history -l
      Operation: purge-history
        Outcome: Succeeded
         Client: pkg
        Version: 216d2efd0c27
           User: root (0)
     Start Time: 2008-11-06T09:33:44
       End Time: 2008-11-06T09:33:44
        Command: /usr/bin/pkg -R /export/home/dc/build_data/pkg_image purge-history

      Operation: uninstall
        Outcome: Succeeded
         Client: pkg
        Version: 216d2efd0c27
           User: jack (65432)
     Start Time: 2008-11-07T14:04:34
       End Time: 2008-11-07T14:04:59
        Command: /usr/bin/pkg -R /a uninstall -q --no-index SUNWslim-utils
    Start State:
		UNEVALUATED:
    -pkg:/SUNWslim-utils@0.5.11,5.11-0.101:20081104T034320Z
     End State:
     pkg:/SUNWslim-utils@0.5.11,5.11-0.101:20081104T034320Z -&gt; None

      Operation: set-authority
        Outcome: Succeeded
         Client: pkg
        Version: 216d2efd0c27
           User: jack (65432)
     Start Time: 2008-11-07T14:05:01
       End Time: 2008-11-07T14:05:01
        Command: /usr/bin/pkg -R /a set-authority --reset-uuid opensolaris.org

      End State:
pkg:/SUNWslim-utils@0.5.11,5.11-0.100:20081025T020505Z -&gt; None

      Operation: install
        Outcome: Failed (Unknown)
         Client: packagemanager
        Version: 71eab3488987
           User: jack (101)
     Start Time: 2008-10-29T11:31:13
       End Time: 2008-10-29T11:32:04
        Command: /usr/bin/packagemanager</screen>
</example>
</task><task id="gijjx"><title>How to Delete Operation History</title><procedure remap="single-step"><step><para>Type the following command to delete all the existing history
information.</para><para><command>$ pfexec pkg purge-history</command></para>
</step>
</procedure>
</task><task id="gijkz"><title>How to View the List of Available Commands</title><procedure remap="single-step"><step><para>Type the following command to view the list of available commands.</para><para><command>$ pkg help</command></para>
</step>
</procedure>
</task>
</sect1>
</chapter>