FreeBSD changing pkg_add package ftp site location

pkg_add is a utility for installing software package distributions. It works like Linux apt-get command. It can download package from freebsd ftp site with the remote fetching feature. This will determine the appropriate objformat and release and then fetch and install the package. You can use following syntax:
pkg_add -v -r {package-name}

For example, you can install vim package:

# pkg_add -v -r vim

By default it downloads, the package from if this site is too busy then you need to use other ftp site location. You can define the environment variable PACKAGEROOT specifies an alternate location for pkg_add to fetch from. The fetch URL is built using this environment variable and the automatic directory logic that pkg_add uses when the -r option is used. For example:

# pkg_add -v -r vim 

You can select FreeBSD ftp mirror sites list. At the writing of this HONG KONG is nearest mirror for me so I will use

# pkg_add -v -r zip

Besides environment variable PACKAGESITE specifies an alternate location for
pkg_add to fetch from. By default, ftp server uses directory path /pub/FreeBSD/ports/i386/packages-VERSION-release/Latest/. This variable subverts the automatic directory logic that pkg_add uses when the -r option is used. Thus it should be a complete URL to the remote package file(s).

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 11 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
11 comments… add one
  • Anonymous Jan 14, 2006 @ 8:31

    I’ve found that portupgrade suite of tools is a nice alternative to pkg_add, etc… A good starting point is HERE

  • Anonymous Jan 14, 2006 @ 12:04

    Well that method is bit old, it better to use portsnap or cvsup-without-gui. Both are easy for newbie, IMPO

  • Another Anonymous Feb 9, 2009 @ 12:57

    For the record:

    Portsnap and cvsup are entirely different operations than pkg_add and portupgrade, and they cannot be compared at all. It’s like comparing apples to oranges.

    The first 2 programs updates the ports tree, and the other 2 installs packages (portupgrade -P can also start compiling a port if it fails to find a package)

  • Mehul Ved Feb 16, 2009 @ 6:15

    If I am not wrong, export command will work for bourne and bash, but FreeBSD defaults to csh. csh doesn’t support export, one has to use set command in that case. This part has been missed out in the tip.
    It should be, for instance

    set PACKAGEROOT=””

    set PACKAGESITE=””

  • Mehul Ved Feb 16, 2009 @ 6:18

    Sorry, that was a careless mistake, the actual syntax is

    setenv PACKAGEROOT ””

    setenv PACKAGESITE ”

    Remember the trailing /, I did forget to add it 😀

  • Vaggelis Typaldos Aug 27, 2009 @ 9:56

    When installing from the Ports Collection with – make install clean – , there is some way to set your preferred mirror locations? PACKAGEROOT and PACKAGESITE variables serve only for the pkg command?

  • Adam Sep 3, 2009 @ 17:05

    Great tip. Thanks Mehul

  • SIFE Nov 7, 2009 @ 10:00

    Salamo Alikom
    is there way to setup default mirror for ports ?

  • Kuris Apr 5, 2010 @ 5:44

    Excuse me,
    it is possible to set it pernamently?
    To work it also after restart of server?
    I think, that setting of variables is functional only for session…
    There must be some file, where you can write it…
    I will investigate it…

  • Kuris Apr 5, 2010 @ 16:24

    Excuse me, I forgot, It can be easily set in file .profile at users directory…

  • Evildog May 10, 2011 @ 23:44

    IMHO, this could be done by editing /etc/csh.cshrc, if you are usinsg a c shell. csh.cshrc as i understand runs every time c shell is started.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum