# Conda CLI Usage

Use the Conda CLI to download packages through Nexus Repository after you create the repository and configure the Conda client. When authenticated access is required, include credentials in the repository URL. Nexus Repository then retrieves packages from the remote Conda repository, caches them, and returns the cached content to the client.

## Download Packages

Download packages from your Nexus Repository Conda repository by using the `conda install` command with the repository URL:

```
conda install -c <protocol>://<user>:<password>@<hostname>:<port>/repository/<repository_name> <package_name>
```

Where:

- `<protocol>` - The protocol used to connect to Nexus Repository; `HTTP` or `HTTPS`
- `<user>` - The username for Nexus Repository authentication (when required)
- `<password>` - The password for Nexus Repository authentication (when required)
- `<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
- `<package_name>` - The name of the package to download, for example `numpy`

Example:

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

If Nexus Repository requires authentication, append the credentials to the repository URL.

## Retrieve Conda Content

After you configure the Conda client to use Nexus Repository, run Conda commands as usual from your environment. The following commands use Nexus Repository to retrieve package information and package content:

- `conda search` - Searches available packages and displays package information through the configured Nexus Repository
- `conda install` - Downloads and installs packages through the configured Nexus Repository

Example:

```
$ conda install numpy
```

## Upload Conda Packages

To upload packages to a Conda hosted repository, use an HTTP PUT request with `CURL`. The upload path includes the target channel and architecture for the package.

```
curl -u <username>:<password> -X PUT \
  --upload-file <package_file> \
  https://<hostname>/repository/<repository_name>/<channel>/<architecture>/<package_file>
```

Where:

- `<username>` - The username for Nexus Repository authentication.
- `<password>` - The password for Nexus Repository authentication.
- `<package_file>` - The Conda package file to upload. Use a valid `.conda` or `.tar.bz2` package.
- `<hostname>` - The hostname of your Nexus Repository instance.
- `<repository_name>` - The name of the Conda hosted repository in Nexus Repository.
- `<channel>` - The target Conda channel, such as `main`.
- `<architecture>` - The target Conda architecture, such as `linux-64`, `osx-arm64`, or `noarch`.

Example:

```
curl -u admin:admin123 -X PUT \
  --upload-file scipy-1.7.3-py310_0.conda \
  https://nexus.example.com/repository/conda-hosted/myproject/osx-arm64/scipy-1.7.3-py310_0.conda
```

Example for uploading multiple packages:

```
#!/bin/bash
NEXUS_URL="https://nexus.example.com/repository/conda-hosted"
CHANNEL="main"
ARCH="linux-64"
USERNAME="admin"
PASSWORD="admin123"

for package in *.tar.bz2 *.conda; do
  if [ -f "$package" ]; then
    echo "Uploading $package..."
    curl -u "$USERNAME:$PASSWORD" -X PUT \
      --upload-file "$package" \
      "$NEXUS_URL/$CHANNEL/$ARCH/$package"
  fi
done
```

Example when using bearer token for authentication:

```
curl -H "Authorization: Bearer YOUR_TOKEN" -X PUT \
  --upload-file package.tar.bz2 \
  https://nexus.example.com/repository/conda-hosted/main/linux-64/package.tar.bz2
```

After a successful upload, Nexus Repository automatically updates repository metadata.
