# why pkg upgrade will install new packages?



## meteor8488 (Jun 29, 2018)

Hi All,

I'm running php-fpm on my server. Usually I'll go to /usr/port/lang/php71, and then run "make config" to select all the php modules I need, and also remove the default ones which I don't need.

But today after I upgrade FreeBSD from 11.1 to 11.2, when I run pkp upgrade, pkg is trying to install some new php module which I didn't install before.


php module I installed


```
# pkg version -v |grep php
php71-7.1.18                       <   needs updating (index has 7.1.19)
php71-ctype-7.1.18                 <   needs updating (index has 7.1.19)
php71-curl-7.1.18                  <   needs updating (index has 7.1.19)
php71-dom-7.1.18                   <   needs updating (index has 7.1.19)
php71-exif-7.1.18                  <   needs updating (index has 7.1.19)
php71-extensions-1.0               =   up-to-date with index
php71-filter-7.1.18                <   needs updating (index has 7.1.19)
php71-gd-7.1.18                    <   needs updating (index has 7.1.19)
php71-hash-7.1.18                  <   needs updating (index has 7.1.19)
php71-iconv-7.1.18                 <   needs updating (index has 7.1.19)
php71-json-7.1.18                  <   needs updating (index has 7.1.19)
php71-mbstring-7.1.18              <   needs updating (index has 7.1.19)
php71-mcrypt-7.1.18                <   needs updating (index has 7.1.19)
php71-memcache-3.0.9               =   up-to-date with index
php71-mysqli-7.1.18                <   needs updating (index has 7.1.19)
php71-opcache-7.1.18               <   needs updating (index has 7.1.19)
php71-openssl-7.1.18               <   needs updating (index has 7.1.19)
php71-session-7.1.18               <   needs updating (index has 7.1.19)
php71-tokenizer-7.1.18             <   needs updating (index has 7.1.19)
php71-xml-7.1.18                   <   needs updating (index has 7.1.19)
php71-zip-7.1.18                   <   needs updating (index has 7.1.19)
php71-zlib-7.1.18                  <   needs updating (index has 7.1.19
```



```
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking for upgrades (64 candidates): 100%
Processing candidates (64 candidates): 100%
The following 59 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
    oniguruma: 6.8.1
    libXpm: 3.5.12
    xproto: 7.0.31
    libXext: 1.3.3_1,1
    xextproto: 7.3.0
    libXau: 1.0.8_3
    libX11: 1.6.5,1
    libxcb: 1.12_2
    libXdmcp: 1.1.2
    libpthread-stubs: 0.4
    kbproto: 1.0.7
    libXt: 1.1.5,1
    libSM: 1.2.2_3,1
    libICE: 1.0.9_1,1
    jpeg-turbo: 1.5.3
[B]    php71-xmlwriter: 7.1.18
    php71-xmlreader: 7.1.18
    php71-simplexml: 7.1.18
    php71-posix: 7.1.18
    php71-sqlite3: 7.1.18
    sqlite3: 3.22.0_2
    readline: 7.0.3_1
    php71-pdo_sqlite: 7.1.18
    php71-pdo: 7.1.18
    php71-phar: 7.1.18[/B]
    libnghttp2: 1.31.1

Installed packages to be UPGRADED:
    luajit: 2.0.5 -> 2.0.5_1
    libzip: 1.3.0 -> 1.3.2
    libxml2: 2.9.4 -> 2.9.7
    liblz4: 1.8.0,1 -> 1.8.1.2,1
    libffi: 3.2.1_1 -> 3.2.1_2
    libevent: 2.1.8 -> 2.1.8_1
    indexinfo: 0.2.6 -> 0.3.1
    freetype2: 2.8 -> 2.8_2
    cyrus-sasl: 2.1.26_12 -> 2.1.26_13
    GeoIP: 1.6.11 -> 1.6.12

Installed packages to be REINSTALLED:
    screen-4.6.2 (options changed)
    ruby24-bdb-0.6.6_5 (options changed)
    ruby-2.4.4,1 (options changed)
    rsync-3.1.3 (options changed)
    portupgrade-2.4.16,2 (options changed)
    php71-openssl-7.1.18 (direct dependency changed: php71)
    php71-memcache-3.0.9 (options changed)
    php71-mbstring-7.1.18 (direct dependency changed: oniguruma)
    php71-gd-7.1.18 (options changed)
    php71-extensions-1.0 (options changed)
    php71-7.1.18 (options changed)
    p5-MIME-Base64-3.15 (needed shared library changed)
    openssl-1.0.2o_4,1 (options changed)
    mysql56-server-5.6.40 (direct dependency changed: perl5)
    mysql56-client-5.6.40 (direct dependency changed: perl5)
    logwatch-7.4.3 (options changed)
    libunwind-20170615 (options changed)
    libiconv-1.14_11 (options changed)
    jpeg-8_7 (options changed)
    google-perftools-2.6.3 (options changed)
    db5-5.3.28_6 (options changed)
    curl-7.60.0 (options changed)
    ca_root_nss-3.37.3 (options changed)

Number of packages to be installed: 26
Number of packages to be upgraded: 10
Number of packages to be reinstalled: 23
```


In the past I always use portupgrade to upgrade packages.

And another question is that it seems pkg upgrade will upgrade some package intead of upgrade all packages, why?

For example, if I check pkg version, all below packages need to be upgraded.


```
# pkg version -v | grep "<"
GeoIP-1.6.11                       <   needs updating (index has 1.6.12)
ca_root_nss-3.37.3                 <   needs updating (index has 3.38)
cyrus-sasl-2.1.26_12               <   needs updating (index has 2.1.26_13)
freetype2-2.8                      <   needs updating (index has 2.9.1)
indexinfo-0.2.6                    <   needs updating (index has 0.3.1)
libevent-2.1.8                     <   needs updating (index has 2.1.8_1)
libffi-3.2.1_1                     <   needs updating (index has 3.2.1_2)
liblz4-1.8.0,1                     <   needs updating (index has 1.8.2,1)
libxml2-2.9.4                      <   needs updating (index has 2.9.7)
libzip-1.3.0                       <   needs updating (index has 1.5.1)
luajit-2.0.5                       <   needs updating (index has 2.0.5_1)
nginx-1.14.0_4,2                   <   needs updating (index has 1.14.0_6,2)
php71-7.1.18                       <   needs updating (index has 7.1.19)
php71-ctype-7.1.18                 <   needs updating (index has 7.1.19)
php71-curl-7.1.18                  <   needs updating (index has 7.1.19)
php71-dom-7.1.18                   <   needs updating (index has 7.1.19)
php71-exif-7.1.18                  <   needs updating (index has 7.1.19)
php71-filter-7.1.18                <   needs updating (index has 7.1.19)
php71-gd-7.1.18                    <   needs updating (index has 7.1.19)
php71-hash-7.1.18                  <   needs updating (index has 7.1.19)
php71-iconv-7.1.18                 <   needs updating (index has 7.1.19)
php71-json-7.1.18                  <   needs updating (index has 7.1.19)
php71-mbstring-7.1.18              <   needs updating (index has 7.1.19)
php71-mcrypt-7.1.18                <   needs updating (index has 7.1.19)
php71-mysqli-7.1.18                <   needs updating (index has 7.1.19)
php71-opcache-7.1.18               <   needs updating (index has 7.1.19)
php71-openssl-7.1.18               <   needs updating (index has 7.1.19)
php71-session-7.1.18               <   needs updating (index has 7.1.19)
php71-tokenizer-7.1.18             <   needs updating (index has 7.1.19)
php71-xml-7.1.18                   <   needs updating (index has 7.1.19)
php71-zip-7.1.18                   <   needs updating (index has 7.1.19)
php71-zlib-7.1.18                  <   needs updating (index has 7.1.19)
pkg-1.10.5                         <   needs updating (index has 1.10.5_1)
```

But if you check the pkg upgrade output, only below packages will be upgraded



```
Installed packages to be UPGRADED:
    luajit: 2.0.5 -> 2.0.5_1
    libzip: 1.3.0 -> 1.3.2
    libxml2: 2.9.4 -> 2.9.7
    liblz4: 1.8.0,1 -> 1.8.1.2,1
    libffi: 3.2.1_1 -> 3.2.1_2
    libevent: 2.1.8 -> 2.1.8_1
    indexinfo: 0.2.6 -> 0.3.1
    freetype2: 2.8 -> 2.8_2
    cyrus-sasl: 2.1.26_12 -> 2.1.26_13
    GeoIP: 1.6.11 -> 1.6.12
```

can some one help to explain?
Thanks


----------



## rigoletto@ (Jun 29, 2018)

The answer probably is bellow on those *(options changed)* etc. messages. If you want to investigate run (for instance, after the upgrade) `pkg info -r php71-xmlwriter` to see what is pulling it, then go to the commit messages, like on FreshPorts, and look what changed on the related ports.

So, yes, this kind of behavior is usually normal.


----------



## meteor8488 (Jun 29, 2018)

lebarondemerde said:


> The answer probably is bellow on those *(options changed)* etc. messages. If you want to investigate run (for instance, after the upgrade) `pkg info -r php71-xmlwriter` to see what is pulling it, then go to the commit messages, like on FreshPorts, and look what changed on the related ports.
> 
> So, yes, this kind of behavior is usually normal.


Thanks for your quickly response..

Do you mean I need to install these packages first, then run the command to check why it's installed? And then I remove it..


----------



## Crivens (Jun 29, 2018)

You also seem to mix ports and packages. Please expect all kinds of problems from this.


----------



## rigoletto@ (Jun 29, 2018)

Just use `pkg upgrade`, but if you have mixed packages and ports, as suggested, `pkg upgrade -f` (to force the reinstall of all packages).


----------



## phoenix (Jun 29, 2018)

Binary packages are built using the default set of OPTIONS for a port.

If you install a port manually and change the OPTIONS, then you will end up with something that's different from the binary package.  If you try to upgrade the installed port via binary package, it will revert to the default set of OPTIONS, and pull in a different set of dependencies.

IOW, it's working as designed, and you have discovered one of the main reasons you should not mix ports and packages.

If your needs match the default set of OPTIONS, then use only binary packages.

If your needs require specific OPTIONS, then only use the ports tree.

If you want the best of both worlds (custom OPTIONS, but simple binary upgrades), then you need to make your own custom repo using poudriere or synth, and install the binary packages from there.


----------



## meteor8488 (Jul 1, 2018)

phoenix said:


> Binary packages are built using the default set of OPTIONS for a port.
> 
> If you install a port manually and change the OPTIONS, then you will end up with something that's different from the binary package.  If you try to upgrade the installed port via binary package, it will revert to the default set of OPTIONS, and pull in a different set of dependencies.
> 
> ...




Thanks for this information. Now I understand that I should not use pkg upgrade if I installed software via ports.



If I prefer to use port to install/upgrade software, after major version upgrade, I need to use  "portupgrade -af" not pkg upgrade, right?


----------



## Crivens (Jul 1, 2018)

What I do is I have made a script which installs/builds all I need. When versions change too much, I clear out all packages and rebuild it all. This also clears out the cruft of stuff I installed once for one job and which would then drag along for years to come.


----------



## phoenix (Jul 2, 2018)

meteor8488 said:


> Thanks for this information. Now I understand that I should not use pkg upgrade if I installed software via ports.
> 
> If I prefer to use port to install/upgrade software, after major version upgrade, I need to use  "portupgrade -af" not pkg upgrade, right?



Portupgrade or portmaster can be used for that. Both are under active maintenance, and portmaster is currently being rewritten to support all the new, fancy features of the ports tree (not yet released, though).


----------

