# Configure Conda with Nexus

Conda repositories are commonly referred to as channels. A channel is an online location where Conda stores and retrieves packages. Conda clients search one or more channels when resolving packages.

Configure the Conda client to use Nexus before you download or upload packages. Conda uses the optional `.condarc` runtime configuration file to define settings such as channels and environment directories. Note that a Nexus Conda repository must exist in Nexus before configuring the client.

Conda can be configured in the following methods:

- Update the available channels
- Set the default channels
- Set the channel alias

## Update the Available Channels

Listing channel locations in `.condarc` overrides Conda defaults, so Conda searches only the listed channels in the given order. When using the Conda client with Nexus Repository, add the Nexus Conda repository in `.condarc` and remove the default channels:

```
conda config --add channels <protocol>://<authentication>@<hostname>:<port>/repository/<repository_name>
conda config --remove channels defaults
```

Where:

- `<protocol>` - The protocol used to connect to Nexus Repository; `HTTP` or `HTTPS`
- `<authentication>` - See [Authentication Methods](https://help.sonatype.com/en/configure-conda-with-nexus.html#authentication-methods "Authentication Methods")
- `<hostname>` - The hostname of your Nexus Repository instance
- `<port>` - The port used by your Nexus Repository instance
- `<repository_name>` - The name of your Conda repository in Nexus Repository

See the [Conda documentation on managing channels](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/settings.html#config-channels)

## Set the Default Channels

In a standard Conda configuration, the `defaults` channel points to multiple channels at [repo.anaconda.com](https://repo.anaconda.com/). If you define `default_channels`, Conda uses that list instead of the standard set. This configuration is useful for air-gapped and enterprise environments where clients must connect only to approved repositories.

```
default_channels:
  - <channel_url>
```

Where,

- `<channel_url>` - The channel URL that Conda should use instead of the standard default channels.

Example:

```
default_channels:
  - http://nexus.example.com:8081/repository/conda-proxy
```

See the [documentation on default channels](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/settings.html#default-channels-default-channels)

## Set the Channel Alias

When you use the `-c` or `--channel` flag with a channel name that is not a URL, Conda prepends the `channel_alias` value to that name. Set `channel_alias` to the URL of your Conda repository to direct those requests through Nexus.

```
channel_alias: <protocol>://<authentication>@<hostname>:<port>/repository/<repository_name>
```

Where:

## Authentication Methods

Nexus Conda repository supports the following authentication methods:

| Authentication method | Suitable for | Distinctive Aspects |
| --- | --- | --- |
| Basic authentication | Simple configurations using HTTPS or a trusted network. | Easy to set up, but exposes credentials in the URL. |
| `.netrc` file | Secure and maintainable option for local development or shared configuration patterns. | Recommended method. Keeps credentials separate from the repository URL. |
| Environment variables | CI/CD or scripted environments. | Useful for automation and secret injection. Keeps credentials out of static configuration files, but still depends on how the runtime environment manages secrets. |

### Basic Authentication

**Note**

Use this method only on trusted networks or with HTTPS.

Basic authentication embeds username and password within URL. For example:

```
https://<username>:<password>@<hostname>:<port>/repository/<repository_name>
```

Example for setting the channel defaults:

```
conda config --add channels https://admin:admin123@nexus.example.com:8081/repository/conda-proxy
conda config --remove channels defaults
```

Example for setting the channel alias

```
channel_alias: https://admin:admin123@example.nexus.com:8081/repository/conda-proxy
```

### .netrc

This method stores credentials in `~/.netrc` on Linux and macOS or `%HOME%\_netrc` on Windows. It prevents you from exposing the credentials within the URL. Take the following steps to authenticate using `.netrc`.

1. Store your credentials to the .netrc file.

```
machine <hostname>
login <username>
password <password>
```

2. On Linux and macOS only, set the file permissions for `.condarc` to retrieve the credentials. Run:

```
chmod 600 ~/.netrc
```

3. Configure the channel without embedded credentials:

```
channels:
  - https://<hostname>:<port>/repository/<repository_name>
```

Example:

1. Store your credentials in the `.netrc` file.

```
machine example.nexus.com
login admin
password admin123
```

2. For Linux and macOS, set the file permissions to retrieve the credentials.

```
chmod 600 ~/.netrc
```

3. Add the channel.

```
conda config --add channels https://example.nexus.com:8081/repository/conda-all
conda config --remove channels defaults
```

If you want to set the channel alias, run:

```
channel_alias: https://example.nexus.com:8081/repository/conda-all
```

### Environment Variables

In shell environments, store credentials in environment variables and reference those variables when you define the repository URL.

```
export CONDA_USERNAME="username"
export CONDA_PASSWORD="password"
```

Example:

1. Set the environmental variables.

```
export CONDA_USERNAME="admin"
export CONDA_PASSWORD="admin123"
```

2. Add the channel. Run:

```
conda config --add channels https://${CONDA_USERNAME}:${CONDA_PASSWORD}@example.nexus.com:8081/repository/conda-all
conda config --remove channels defaults
```

If you want to set the channel alias, run:

```
channel_alias: https://${CONDA_USERNAME}:${CONDA_PASSWORD}@example.nexus.com:8081/repository/conda-all
```
