# Set up personal Anaconda mirror

## Predicaments

If you encounter any problems as follows, you should try to set up a personal Python(Anaconda) mirror:

1. Deploy a python environment on servers that have no access to the Internet;
2. Deploy a python environment which can be used directly by other users on the server;
3. Internet speed or connection to cloud mirror is slow.

## Steps

### Installation

Just install Anaconda according to this guide.

Of course, you can download Anaconda installer archive from here.

You can use wget to mirror the packages from official Anaconda websites or other mirror websites (TUNA and USTC).

If your server is located in China, I recommend the later one.

I’ll take the later one as example.

Create your directory for saving packages:

Save all urls you wanted to links.txt:

Then, edit the download.sh file to download all files in each directory:

Explanations of options:

PS : conda-forge is much larger than others. Of course, you can just download specific version and packages:

Don’t forget to download noarch, otherwise conda won’t work correctly.

Anyway, if your links.txt and download.sh are as same sa mine, you will get this tree of directory:

### Settings

It’s more convenient to save all packages in one directory and just using channel_alias for channels.

Let’s move cloud/conda-forge to anaconda/pkgs.

Now, you can modify the channel_alias and add channels:

Then, check ~/.condarc :

If you prefer command line, you can just use conda config --get :

If you make a mistake during adding channel, you can remove it:

By default, conda now prefers packages from a higher priority channel over any version from a lower priority channel. Therefore, you can now safely put channels at the bottom of your channel list to provide additional packages that are not in the default channels, and still be confident that these channels will not override the core package set.

So, if you want to set the order to free → main → conda-forge, you can rearrange them by terminal or edit the .condarc file directly.

Anyway, you will get this .condarc file:

Content between these dividing lines are wrong according to this answer.

Let’s create a new env named test to prepare for next step (Aggregation).

### Aggregation

What about the ‘anaconda’ channel on anaconda.org at https://anaconda.org/anaconda?
The Anaconda channel on anaconda.org is an aggregated mirror of the packages in https://repo.continuum.io/pkgs/main, https://repo.continuum.io/pkgs/free, and https://repo.continuum.io/pkgs/pro. If you are using conda’s ‘defaults’ channel, you do not need the ‘anaconda’ channel.

Although you’ve downloaded packages, but if you want to install as usual like conda install -c anaconda netcdf4, you have to aggregate /main, /free and /pro.

So, you should create a directory named anaconda under anaconda_mirror.

Then, link all files under each linux-64 and noarch of /main, /free and /pro to linux-64 and noarch under anaconda directory.

Now, you can use conda-build to generates a file repodata.json.

### Update/Install

Now, you can use conda update/install :

Don’t use anaconda channel anymore, because we just have free, main, pro and conda-forge channels.

For example, if you want to install netcdf4 from anaconda channel, don’t specify channel name:

If you have many packaged to install, you can create requirements.txt and install all of them by one command.

Here’s one example of requirements.txt :

If you’re the administrator of the server, you can use system .condarc to set a environment for all users.

You can make conda and any number of packages available to a group of 1 or more users, while preventing these users from installing unwanted packages with conda:

1. Install conda and the allowed packages, if any, in a location that is under administrator control and accessible to users.
2. Create a .condarc system configuration file in the root directory of the installation. This system-level configuration file will override any user-level configuration files installed by the user.

Each user accesses the central conda installation, which reads settings from the user .condarcconfiguration file located in their home directory. The path to the user file is the same as the root environment prefix displayed by conda info, as shown in User configuration file below. The user.condarc file is limited by the system .condarc file.

System configuration settings are commonly used in a system .condarc file but may also be used in a user .condarc file. All user configuration settings may also be used in a system .condarc file.

You can just check the official document about administrator-controlled installation.

Here’s the example of my system .condarc :