This the multi-page printable view of this section.Click here to print.

Return to the regular view of this page.

Using Repository mirrors

How to use the repository mirrors

Table of Contents

1 - APT repository mirrors

How to configure a Linux machine to use APT repository mirrors

Configuring APT to use them

Make certain you make a backup of the files you will be editing below in-case you make a mistake.

Not doing so could cause you not to be able to make any further updates to your machine!

To switch over to using your new proxy you need to edit the apt sources files under /etc/apt/ then run apt-get update.

If you have followed the naming conventions above you can go in to /etc/apt/sources.list and replace any reference to the remote storage url in nexus with the new path.

You should also do this for anything in the /etc/apt/sources.list.d/ directory - but only those you have configured a proxy for!

For example, if your local nexus is accessible at http://10.11.12.13:8081/ then for the apt-ubuntu-archive proxy changing http://gb.archive.ubuntu.com/ubuntu in sources.list with http://10.11.12.13:8081/repository/apt-ubuntu-archive/

For example:

1deb http://gb.archive.ubuntu.com/ubuntu focal main restricted
2deb http://gb.archive.ubuntu.com/ubuntu focal-updates main restricted

becomes:

1deb http://10.11.12.13:8081/repository/apt-ubuntu-archive/ focal main restricted
2deb http://10.11.12.13:8081/repository/apt-ubuntu-archive/ focal-updates main restricted
Do not change the distribution field, e.g. focal-updates above. They should match that of the remote repository. Do not replace them with the value in the proxy!

If like me, you have https configured, then you should be using the correct https address and not the 8081 port.

Now run an update:

1sudo apt-get update

Apt should now access your local proxy. If this completes without any errors then any future upgrade or install will now use the proxy instead.

2 - NPM repository mirrors

How to configure NPM use an NPM repository mirror

Configuring NPM to use Nexus as a proxy is simple.

First ensure you've created the NPM proxy.

Next, edit or create the file .npmrc in your home directory with the following line:

1registry=http://10.11.12.13:8081/repository/npm-proxy

Where 10.11.12.13 is where you have deployed Nexus and npm-proxy is what you called your NPM proxy. If you've configured a group then use the group's name instead, e.g. npm-group

Obviously if you've configured https and dns then use that and not port 8081.

Now any time you run npm it will use your proxy.

3 - PyPi repository mirrors

How to configure PIP use a PyPi repository mirror

Configuring PIP to use Nexus as a proxy is simple.

First ensure you've created the PyPi proxy.

Next, we need to edit or create pip.conf to hold the new index position. This file can be in one of three locations:

Global
If it exists then ${XDG_CONFIG_DIRS}/pip.conf will be loaded, followed by /etc/pip.conf.
User
${HOME}/.config/pip/pip.conf for the specific user. There is a legacy option of ${HOME}/.pip/pip.conf which will be used if it exists.
Site
For virtual environments then ${VIRTUAL_ENV}/pip.conf

pip.conf

pip.conf should contain the following:

1[global]
2index = http://10.11.12.13:8081/repository/pypi-group/pypi
3index-url = http://10.11.12.13:8081/repository/pypi-group/simple

Where 10.11.12.13 is where you have deployed Nexus and pypi-proxy is what you called your PyPi proxy. If you've configured a group then use the group's name instead, e.g. pypi-group

Obviously if you've configured https and dns then use that and not port 8081.

Now any time you run pip it will use your proxy.

Further reading