# pkg update error



## G4 (Feb 28, 2020)

Hi all,

I'm getting the following error on my FreeBSD 12.1-RELEASE-p2:


```
# pkg update
Updating FreeBSD_latest repository catalogue...
pkg: repository meta has wrong version 2
pkg: Repository FreeBSD_latest load error: meta cannot be loaded No error: 0
Fetching meta.txz: 100%    916 B   0.9kB/s    00:01
pkg: repository meta has wrong version 2
repository FreeBSD_latest has no meta file, using default settings
Fetching packagesite.txz: 100%    6 MiB   1.1MB/s    00:06
pkg: repository meta has wrong version 2
pkg: Repository FreeBSD_latest load error: meta cannot be loaded No error: 0
Unable to open created repository FreeBSD_latest
Unable to update repository FreeBSD_latest
Error updating repositories!
```

This is my pkg config:


```
# pkg -vv
Version                 : 1.11.1
PKG_DBDIR = "/var/db/pkg";
PKG_CACHEDIR = "/var/cache/pkg";
PORTSDIR = "/usr/ports";
INDEXDIR = "";
INDEXFILE = "INDEX-12";
HANDLE_RC_SCRIPTS = false;
DEFAULT_ALWAYS_YES = false;
ASSUME_ALWAYS_YES = false;
REPOS_DIR [
    "/etc/pkg/",
    "/usr/local/etc/pkg/repos/",
]
PLIST_KEYWORDS_DIR = "";
SYSLOG = true;
ABI = "FreeBSD:12:amd64";
ALTABI = "freebsd:12:x86:64";
DEVELOPER_MODE = false;
VULNXML_SITE = "http://vuxml.freebsd.org/freebsd/vuln.xml.bz2";
FETCH_RETRY = 3;
PKG_PLUGINS_DIR = "/usr/local/lib/pkg/";
PKG_ENABLE_PLUGINS = true;
PLUGINS [
]
DEBUG_SCRIPTS = false;
PLUGINS_CONF_DIR = "/usr/local/etc/pkg/";
PERMISSIVE = false;
REPO_AUTOUPDATE = true;
NAMESERVER = "";
HTTP_USER_AGENT = "pkg/1.11.1";
EVENT_PIPE = "";
FETCH_TIMEOUT = 30;
UNSET_TIMESTAMP = false;
SSH_RESTRICT_DIR = "";
PKG_ENV {
}
PKG_SSH_ARGS = "";
DEBUG_LEVEL = 0;
ALIAS {
    all-depends = "query %dn-%dv";
    annotations = "info -A";
    build-depends = "info -qd";
    cinfo = "info -Cx";
    comment = "query -i \"%c\"";
    csearch = "search -Cx";
    desc = "query -i \"%e\"";
    download = "fetch";
    iinfo = "info -ix";
    isearch = "search -ix";
    prime-list = "query -e '%a = 0' '%n'";
    prime-origins = "query -e '%a = 0' '%o'";
    leaf = "query -e '%#r == 0' '%n-%v'";
    list = "info -ql";
    noauto = "query -e '%a == 0' '%n-%v'";
    options = "query -i \"%n - %Ok: %Ov\"";
    origin = "info -qo";
    provided-depends = "info -qb";
    rall-depends = "rquery %dn-%dv";
    raw = "info -R";
    rcomment = "rquery -i \"%c\"";
    rdesc = "rquery -i \"%e\"";
    required-depends = "info -qr";
    roptions = "rquery -i \"%n - %Ok: %Ov\"";
    shared-depends = "info -qB";
    show = "info -f -k";
    size = "info -sq";
}
CUDF_SOLVER = "";
SAT_SOLVER = "";
RUN_SCRIPTS = true;
CASE_SENSITIVE_MATCH = false;
LOCK_WAIT = 1;
LOCK_RETRIES = 5;
SQLITE_PROFILE = false;
WORKERS_COUNT = 0;
READ_LOCK = false;
PLIST_ACCEPT_DIRECTORIES = false;
IP_VERSION = 0;
AUTOMERGE = true;
VERSION_SOURCE = "";
CONSERVATIVE_UPGRADE = true;
PKG_CREATE_VERBOSE = false;
AUTOCLEAN = false;
DOT_FILE = "";
REPOSITORIES {
}
VALID_URL_SCHEME [
    "pkg+http",
    "pkg+https",
    "https",
    "http",
    "file",
    "ssh",
    "ftp",
    "ftps",
    "pkg+ssh",
    "pkg+ftp",
    "pkg+ftps",
]
ALLOW_BASE_SHLIBS = false;
WARN_SIZE_LIMIT = 1048576;
METALOG = "";
OSVERSION = 1201000;
IGNORE_OSVERSION = false;


Repositories:
  FreeBSD_latest: {
    url             : "pkg+http://pkg.FreeBSD.org/FreeBSD:12:amd64/latest",
    enabled         : yes,
    priority        : 0,
    mirror_type     : "SRV",
    signature_type  : "FINGERPRINTS",
    fingerprints    : "/usr/share/keys/pkg"
  }
```

Any thoughts on what might cause the issue?

Thanks!


----------



## Lamia (Feb 28, 2020)

G4 said:


> Repositories: FreeBSD_latest: { url : "pkg+http://pkg.FreeBSD.org/FreeBSD:12:amd64/latest", enabled : yes, priority : 0, mirror_type : "SRV", signature_type : "FINGERPRINTS", fingerprints : "/usr/share/keys/pkg" }



Can you keep this shorter? Mirror_type might not be always necessary; so also pkg+http in URL. You could look up the *Internet for sample conf files.


----------



## G4 (Mar 2, 2020)

This is my /usr/local/etc/pkg/repos/FreeBSD.conf:


```
FreeBSD: { enabled: no }
FreeBSD_latest: {
   url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest",
   mirror_type: "srv",
   signature_type: "fingerprints",
   fingerprints: "/usr/share/keys/pkg",
   enabled: yes
}
```

I would add that I've had the same setup for quite some time and it only recently broke.

Removing the pkg+http scheme results in a deprecation warning.

Even a bare-minimum .conf like so:

```
FreeBSD_latest: {
   url: "http://pkg.FreeBSD.org/${ABI}/latest",
}
```

Results in:

```
# pkg update
Updating FreeBSD repository catalogue...
pkg: repository meta has wrong version 2
pkg: Repository FreeBSD load error: meta cannot be loaded No error: 0
Warning: use of http:// URL scheme with SRV records is deprecated: switch to pkg+http://
Fetching meta.txz: 100%    916 B   0.9kB/s    00:01
pkg: repository meta has wrong version 2
repository FreeBSD has no meta file, using default settings
Warning: use of http:// URL scheme with SRV records is deprecated: switch to pkg+http://
Fetching packagesite.txz: 100%    6 MiB 461.8kB/s    00:14
pkg: repository meta has wrong version 2
pkg: Repository FreeBSD load error: meta cannot be loaded No error: 0
Unable to open created repository FreeBSD
Unable to update repository FreeBSD
Error updating repositories!
```


At any rate, I don't think the problem is with the mirror or the connection, but rather with my local database.


----------



## SirDice (Mar 2, 2020)

Try this first: `pkg-static install -f pkg`. Then follow up with `pkg update -f`.


----------



## G4 (Mar 2, 2020)

```
# pkg-static install -f pkg
Updating FreeBSD repository catalogue...
pkg-static: repository meta has wrong version 2
pkg-static: Repository FreeBSD load error: meta cannot be loaded No error: 0
Fetching meta.txz: 100%    916 B   0.9kB/s    00:01
pkg-static: repository meta has wrong version 2
repository FreeBSD has no meta file, using default settings
Fetching packagesite.txz: 100%    6 MiB   1.1MB/s    00:06
pkg-static: repository meta has wrong version 2
pkg-static: Repository FreeBSD load error: meta cannot be loaded No error: 0
Unable to open created repository FreeBSD
Unable to update repository FreeBSD
Error updating repositories!
```

Looks like there is something wrong with the DB.
I remember reading that automatic backups of the DB are being performed, perhaps it's worth investigating that?


----------



## SirDice (Mar 2, 2020)

G4 said:


> I remember reading that automatic backups of the DB are being performed, perhaps it's worth investigating that?


I don't think your local registration database is at fault, it only complains about the meta data and SQL from the locally cached remote repositories. Try removing /var/db/pkg/FreeBSD.meta, /var/db/pkg/FreeBSD_latest.meta, /var/db/pkg/repo-FreeBSD.sqlite and /var/db/pkg/repo-FreeBSD_latest.sqlite. Then running `pkg update` again. 

Do *NOT* remove /var/db/pkg/local.sqlite (it contains the registrations for your currently installed packages). In case you still want to checkout the backups, they're in /var/backups/.


----------



## G4 (Mar 2, 2020)

Thanks for your suggestions.

Unfortunately it sill gives the same "wrong version 2" error as before:

```
# rm /var/db/pkg/FreeBSD.meta
# rm /var/db/pkg/FreeBSD_latest.meta
# rm /var/db/pkg/repo-FreeBSD.sqlite
# rm /var/db/pkg/
local.sqlite  vuln.xml
# pkg update
Updating FreeBSD repository catalogue...
Fetching meta.txz: 100%    916 B   0.9kB/s    00:01
pkg: repository meta has wrong version 2
repository FreeBSD has no meta file, using default settings
Fetching packagesite.txz: 100%    6 MiB   1.1MB/s    00:06
pkg: repository meta has wrong version 2
pkg: Repository FreeBSD load error: meta cannot be loaded No error: 0
Unable to open created repository FreeBSD
Unable to update repository FreeBSD
Error updating repositories!
```


----------



## tsarya (Mar 2, 2020)

Try updating ports-mgmt/pkg from the ports tree using ports-mgmt/portmaster.
If you haven't fetched the ports tree yet, just do the following:


```
# portsnap fetch
# portsnap extract
```

Once the process is over, assuming you have ports-mgmt/portmaster installed already, run:

```
# portmaster pkg
```
 
At the end, you should see pkg version 1.13.2 installed (at the time of writing this post)

After I did the above, I got this:

```
# pkg upgrade -F
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking for upgrades (3 candidates): 100%
Processing candidates (3 candidates): 100%
Checking integrity... done (0 conflicting)
Your packages are up to date.
```


----------



## G4 (Mar 3, 2020)

Thanks, that did the trick.
Now I've stumbled onto https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=244549, but a fix will come soon.


----------



## merouleau (Apr 8, 2020)

I have the same problem. The two portsnap commands worked, but I'm blocked on the "portmaster pkg" step as it is not installed, and "pkg install portmaster" also produces a "wrong version 2" error. Any ideas?


----------



## tingo (Apr 8, 2020)

If you are using ports (your mention of portsnap...), what happens if you try to build pkg from ports manually?
like this:

```
cd /usr/ports/ports-mgmt/pkg
make install clean
cd
```


----------



## getopt (Apr 9, 2020)

tingo said:


> what happens ...


See the example from Chapter 4.5.1. Installing Ports in the FreeBSD Handbook.


----------



## merouleau (Apr 9, 2020)

Thanks for your replies. I can see how that likely would have worked.

Yesterday I continued playing with it and decided to upgrade since I was running an unsupported release (11.0). At some point in the process of moving to 12.1 I wound up with a new enough version of pkg that I was able to overcome the issue using the technique above. And now my server is up to date. 

The upgrade went smoothly with no disruption to my local configurations - kudos to the FreeBSD team!


----------



## jef (Apr 10, 2020)

I've been running into this with 12.0-RELEASE to 12.1-RELEASE and freebsd-update

After a lot of frustration, I've had some success with (using the repo of your architecture and quarterly/latest choice)


```
fetch https://pkg.freebsd.org/FreeBSD:12:amd64/latest/All/pkg-1.14.2.txz
sudo pkg add -f pkg-1.14.2.txz
```

pkg-add(8) suggests that


```
sudo pkg add -f https://pkg.freebsd.org/FreeBSD:12:amd64/latest/All/pkg-1.14.2.txz
```
would work as a one-liner, though I have not _now _tried it _successfully_.


----------



## ecazamir (Apr 10, 2020)

I got into this error after updating from 12.0-RELEASE to 12.1-RELEASE. 
The solution that worked for me was to forcibly remove pkg 


```
root@server:/var/db/pkg # pkg update -f
Updating FreeBSD repository catalogue...
pkg: repository meta /var/db/pkg/FreeBSD.meta has wrong version 2
pkg: Repository FreeBSD load error: meta cannot be loaded No error: 0
Fetching meta.txz: 100%    916 B   0.9kB/s    00:01
pkg: repository meta /var/db/pkg/FreeBSD.meta has wrong version 2
repository FreeBSD has no meta file, using default settings
Fetching packagesite.txz: 100%    6 MiB  70.9kB/s    01:31
pkg: repository meta /var/db/pkg/FreeBSD.meta has wrong version 2
pkg: Repository FreeBSD load error: meta cannot be loaded No error: 0
Unable to open created repository FreeBSD
Unable to update repository FreeBSD
Error updating repositories!
root@server:/var/db/pkg # pkg add -f https://pkg.freebsd.org/FreeBSD:12:amd64/latest/All/pkg-1.14.2.txz
Certificate verification failed for /C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3
34374852608:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:/usr/src/crypto/openssl/ssl/statem/statem_clnt.c:1915:
Certificate verification failed for /C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3
34374852608:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:/usr/src/crypto/openssl/ssl/statem/statem_clnt.c:1915:
Certificate verification failed for /C=US/O=Let's


root@server:/var/db/pkg # pkg delete -f pkg
Checking integrity... done (0 conflicting)
Deinstallation has been requested for the following 1 packages (of 0 packages in the universe):

Installed packages to be REMOVED:
    pkg-1.10.5_5

Number of packages to be removed: 1

The operation will free 13 MiB.

Proceed with deinstalling packages? [y/N]: y
[1/1] Deinstalling pkg-1.10.5_5...
[1/1] Deleting files for pkg-1.10.5_5: 100%
root@server:/var/db/pkg # pkg update -f pkg
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:12:amd64/quarterly, please wait...
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
Installing pkg-1.13.2...
Extracting pkg-1.13.2: 100%
Usage: pkg update [-fq] [-r reponame]

For more information, see 'pkg help update'.
root@server:/var/db/pkg # pkg update
Updating FreeBSD repository catalogue...
Fetching meta.conf: 100%    163 B   0.2kB/s    00:01
Fetching packagesite.txz: 100%    6 MiB 280.4kB/s    00:23
Processing entries: 100%
FreeBSD repository update completed. 31492 packages processed.
All repositories are up to date.
root@server:/var/db/pkg # pkg upgrade
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Updating database digests format: 100%
Checking for upgrades (19 candidates): 100%
Processing candidates (19 candidates): 100%
The following 19 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
    python37: 3.7.7

Installed packages to be UPGRADED:
    fusefs-libs: 2.9.7 -> 2.9.9_1
    gawk: 4.1.4_3 -> 5.0.0
    gettext-runtime: 0.19.8.1_2 -> 0.20.1
    glib: 2.56.3_2,1 -> 2.56.3_7,1
    haproxy: 1.8.17 -> 2.0.13
    icu: 63.1_1,1 -> 66.1,1
    libdnet: 1.12_1 -> 1.13_3
    libmspack: 0.9.1 -> 0.10.1
    libssh2: 1.8.0,3 -> 1.8.2,3
    libxml2: 2.9.7 -> 2.9.10
    nginx: 1.14.2_3,2 -> 1.16.1_12,2
    open-vm-tools-nox11: 10.3.0_1,2 -> 11.0.1_3,2
    pcre: 8.42_1 -> 8.43_2
    perl5: 5.28.1 -> 5.30.2
    postfix: 3.3.3,1 -> 3.5.0,1
    python27: 2.7.15 -> 2.7.17_1
    readline: 7.0.5 -> 8.0.4
    sudo: 1.8.27 -> 1.8.31p1

Number of packages to be installed: 1
Number of packages to be upgraded: 18

The process will require 114 MiB more space.
62 MiB to be downloaded.
```


----------



## SirDice (Apr 10, 2020)

Try `pkg-static install -f pkg` or `pkg bootstrap -f`


----------



## ecazamir (Apr 10, 2020)

The first option didn't work for me. I see the 2nd one for the first time now, I have no clue if it works or not, the problem was solved on my side.


----------



## SirDice (Apr 10, 2020)

ecazamir said:


> I see the 2nd one for the first time now


You can learn a lot from the man pages 


```
bootstrap
             This is for compatibility with the pkg(7) bootstrapper.  If pkg
             is already installed, nothing is done.

             If invoked with the -f flag an attempt will be made to reinstall
             pkg from remote repository.
```
See pkg(8) and pkg(7).


----------



## DarkDon (Apr 10, 2020)

pkg delete -f pkg

pkg install pkg


----------



## dvl@ (Apr 17, 2020)

SirDice said:


> Try `pkg-static install -f pkg` or `pkg bootstrap -f`



`pkg bootstrap -f` is what got us going.


----------



## dvl@ (Apr 20, 2020)

This just in, it's on 11.3 as well: https://lists.freebsd.org/pipermail/freebsd-cloud/2020-April/000234.html


----------



## jjvereijken (May 3, 2020)

For me:

`sudo pkg bootstrap -f; sudo pkg update -f`

got me back in business!


----------



## LITMK (Jul 14, 2020)

ecazamir said:


> I got into this error after updating from 12.0-RELEASE to 12.1-RELEASE.
> The solution that worked for me was to forcibly remove pkg
> 
> 
> ...


Same thing for me 12.0 to 12.1 and removing and then bootstrapping worked! Thanks!


----------



## tuaris (Jul 29, 2020)

This seems to be a chronic problem with 12.0 to 12.1 upgrades.  I had 3 systems so far exhibit the same problem.  The solution is


```
pkg bootstrap -f
pkg update -f
```

Then you can proceed with `pkg upgrade -fy` as requested by freebsd-update()
(I figured I might as well add this for myself and others since this post is the first/second result on search engines)


----------



## Ytachi1000 (Oct 9, 2020)

I had the same problem , seems  `pkg bootstrap -f` solve it. Thank you.


----------



## parashiva (Feb 3, 2021)

jef said:


> I've been running into this with 12.0-RELEASE to 12.1-RELEASE and freebsd-update
> 
> After a lot of frustration, I've had some success with (using the repo of your architecture and quarterly/latest choice)
> 
> ...



Thank you in advance.
I have a freebsd box last active in 2019.04 12.0R, your solution help me a lot, it working now.


----------



## ricardo.volpato (Feb 23, 2021)

Here, I'm running into FreeBSD 12.0-STABLE r341991  amd64.
Issuing "# pkg bootstrap -f" make the pkg update work again.


----------



## SirDice (Feb 23, 2021)

ricardo.volpato said:


> I'm running into FreeBSD 12.0-STABLE r341991 amd64.


FreeBSD 12.0 is end-of-life since February 2020. 12.0-STABLE doesn't exist anymore, -STABLE moved on, it's 12.2-STABLE now. But I suggest you take this opportunity to do a source upgrade to releng/12.2. From that point onward you can use freebsd-update(8) to keep your system updated. -STABLE can only be updated/upgraded by building from source. 



ricardo.volpato said:


> Issuing "# pkg bootstrap -f" make the pkg update work again.


Packages are built for 12.2, so this is going to cause problems for you.


----------



## rainer_d (Feb 23, 2021)

I also hit this updating FreeBSD 12.0 with a 2019Q3 cut (my own poudriere) to 2021Q1.
pkg add -f pkg-1.16.3.txz  (downloaded locally) did indeed do the trick.

Usually, it's enough to extract pkg-static and run with that. But not this time.


----------



## SirDice (Apr 14, 2021)

rainer_d said:


> I also hit this updating FreeBSD 12.0


Do I really need to state it again? FreeBSD 12.0 is end-of-life. Not supported anymore. Please stop using outdated versions.


----------



## rainer_d (Apr 14, 2021)

SirDice said:


> Do I really need to state it again? FreeBSD 12.0 is end-of-life. Not supported anymore. Please stop using outdated versions.


I updated to 12.2. From 12.0.


----------



## dvl@ (Apr 14, 2021)

Happy with 12.2 so far?


----------



## rainer_d (Apr 14, 2021)

Sure. I've updated probably around 20 hosts.
I just hope that the update to the smartpqi(4) driver that currently sits in a differential and that I plan to install on Monday finally fixes the crashes and hangs I have had with this hardware.


----------



## dvl@ (Apr 14, 2021)

At $WORK we're about to update our poudriere server to 13.x - that's always the first host to move.


----------



## rainer_d (Apr 14, 2021)

My poudriere-server is a Gen8 HP DL 380. It now takes about a day to build all the packages I need - that unfortunately includes libreoffice and three different versions of llvm.

I'm not moving to 13, yet. 

My biggest problem are all the old servers with anything between FreeBSD 8 and 11 that cannot easily be migrated because they mostly contain old websites that wouldn't work on anything newer anyway...


----------



## dvl@ (Apr 14, 2021)

rainer_d said:


> My biggest problem are all the old servers with anything between FreeBSD 8 and 11 that cannot easily be migrated because they mostly contain old websites that wouldn't work on anything newer anyway...


Put them into jails on newer hosts?


----------



## rainer_d (Apr 15, 2021)

I may have to re-visit that - but most are running chrooted php-fpm instances via nullfs mounted base- and local directories.

AFAIK, there's no nullfs in a jail and I'd have to manually mount it from outside...which is why I went the route of having multiple PHP-versions in parallel...

It's a rabbit-hole I have not wanted to go down, yet. HP hardware does work surprisingly well, even beyond 10 years in service ;-)


----------



## rainer_d (Apr 15, 2021)

Adding to that: a lot of the hostings are "dead" (in that the customers have moved them elsewhere), but some are still being paid despite that and nobody has time to sort it out...


----------

