RHEL BasedRocky Linux

How To Install Miniconda on Rocky Linux 9

Install Miniconda on Rocky Linux 9

Rocky Linux 9 is a community-driven enterprise-grade operating system that offers a stable, secure, and high-performance foundation suitable for servers, desktops, and virtual machines. It inherits its lineage from Red Hat Enterprise Linux, providing long-term support and consistency. Meanwhile, Miniconda is a lightweight installer for conda, Python, and a minimal set of packages. By leveraging Miniconda on Rocky Linux 9, it becomes straightforward to manage Python environments, install packages for data science or web development, and streamline version control for specialized projects. Combining the stability of Rocky Linux 9 with Miniconda’s flexible nature offers a reliable platform for modern development needs. This guide explains each step in detail, from initial prerequisites to environment management techniques. It also provides practical tips for troubleshooting and ensuring a seamless installation experience.

Prerequisites

Ensuring that all essential prerequisites are in place helps avoid interruptions during the installation. The minimum recommended hardware for Rocky Linux 9 includes at least 2 GB of RAM, a functioning internet connection, and about 400 MB of free disk space to accommodate Miniconda’s basic packages. Additional space is typically necessary for extensive Python library installations. In most scenarios, a non-root user with sudo privileges is best for system-wide changes. This safeguards system integrity. For installations on cloud instances or local servers, confirm that you can run basic commands (such as sudo yum update) without restrictions. The following items are key prerequisites:

  • A fully updated Rocky Linux 9 system. Running sudo dnf -y upgrade ensures the system is current.
  • Access to the curl or wget utilities to download the Miniconda installer.
  • An active internet connection for retrieving packages.
  • Sufficient permissions to create directories in the chosen installation path.

Pre-Installation Steps

Prior to installing Miniconda, it is helpful to prepare the system by updating all existing packages. Close any nonessential processes to avoid resource conflicts. The following sequence outlines the main actions:

System Update

Use the command below to synchronize system packages:

sudo dnf -y update

This refreshes repositories and upgrades software to the latest stable versions, ensuring compatibility and security. It also helps in preventing issues that may arise from outdated libraries or dependencies.

Install Important Dependencies

Although Miniconda itself does not require many dependencies, some system libraries often prove beneficial for various Python packages. For instance, unzip, git, or SSL libraries might be necessary:

sudo dnf install -y bzip2 git openssl curl

This ensures that the system can handle compression, secure connections, and version control before adding more advanced data science or development libraries.

Verify Disk Space

Before downloading Miniconda, it is wise to confirm that the target partition has enough free space. A basic check can be done using:

df -h

If the destination folder has limited capacity, either free space or specify an alternative directory during installation.

Downloading and Verifying Miniconda

Miniconda can be downloaded from the official repository. Select the installer matching Rocky Linux 9 architecture (commonly x86_64 on most machines):

curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

This command retrieves the latest Miniconda installation script. Once downloaded, verify the integrity of the file with:

sha256sum Miniconda3-latest-Linux-x86_64.sh

Compare the resulting SHA-256 hash against the official checksums. Matching hashes confirm a tamper-free installer. Verifying integrity is highly recommended to avoid corrupted installations or security risks.

Installation Process

Once the script is in place, the next step involves running the interactive shell-based installer. It prompts for confirmation of the software license, the target installation path, and optional environment variables. The entire sequence is outlined below.

Running the Installer

bash Miniconda3-latest-Linux-x86_64.sh

This initiates the guided installation. Press Enter to start, then review the license. When prompted, accept the license terms by typing yes. Next, confirm the desired installation path. By default, Miniconda installs to ~/miniconda3. It is possible to set a custom location, especially if disk space or user permission requirements demand it.

Adding Miniconda to the PATH

By default, the installer offers the option to add Miniconda to the PATH environment variable. Accepting this allows immediate usage of the conda command without additional steps. If the interactive prompt does not appear or was skipped, Miniconda can still be activated manually:

source ~/miniconda3/bin/activate
conda init bash

The conda init bash command sets up Miniconda to load automatically whenever a new shell session is started. For alternative shells, use conda init zsh or conda init fish, depending on user preference.

Post-Installation Configuration

After the installer finishes, certain configurations help optimize workflows with conda. These range from ensuring that the environment loads properly to customizing channel priorities for specialized package repositories.

Verifying the Installation

Confirm success by checking the conda version:

conda --version

A successful readout indicates success. Additional verification can be done by listing packages:

conda list

This displays the packages pre-installed in the base environment, indicating that the core features of Miniconda are functional.

Shell Initialization

If auto-activation was skipped, initialization must be done manually. This saves time in repetitive tasks. For example:

conda init bash

Opening a new terminal session or reloading the current one with source ~/.bashrc then ensures that conda is readily available in every new shell. This avoids needing to type the full path to the conda binary.

Configuring Channels

Conda obtains packages from configured channels. By default, it points to the primary channel that hosts stable distributions of many libraries. Enabling or disabling channels like conda-forge can add broader coverage:

conda config --add channels conda-forge

Relying on the conda-forge channel is beneficial when you require some of the latest or alternative versions of certain libraries. Setting channel_priority is another advanced option to handle conflicts gracefully:

conda config --set channel_priority flexible

This approach often resolves environment-solving issues, particularly in complex data science configurations.

Environment Management

One of Miniconda’s strongest features is environment management. Isolated environments prevent version conflicts and simplify sharing of reproducible setups. They also keep the system’s global Python library intact.

Creating New Environments

A new environment called myenv can be generated with:

conda create --name myenv python=3.9

This command sets Python 3.9 within the environment while the base system remains untouched. It is possible to add more packages at this step by adding them after Python, like:

conda create --name data-env python=3.9 numpy pandas matplotlib

This bundling approach ensures data analysis tasks can be handled cohesively.

Activating and Deactivating Environments

Work inside an environment by activating:

conda activate myenv

The command-line prompt changes, indicating the active environment. After finishing tasks, return to the base environment:

conda deactivate

Maintaining distinct environments fosters efficient organization of libraries and reduces the probability of library version mismatches.

Installing and Removing Packages

Inside an active environment, adding software is straightforward:

conda install requests

To remove a package cleanly:

conda remove requests

Each environment thus gains tailored capabilities. This approach is much more stable than installing everything system-wide. Python data science, machine learning, or web frameworks remain sandboxed from each other, reducing the chance of conflicting dependencies.

Listing and Cloning Environments

A quick overview of existing environments is found using:

conda env list

Environments can also be cloned to rapidly replicate a setup:

conda create --name myenvclone --clone myenv

This technique duplicates the environment packages and versions, simplifying distribution among team members or redeploying setups on different servers.

Advanced Configurations

While Miniconda works out-of-the-box in many scenarios, certain advanced settings hone the user experience or expand functionality. These customizations increase productivity, especially in routine tasks.

auto_activate_base Settings

Some users favor automatically activating the base environment with every new shell. Others avoid this. Adjust with:

conda config --set auto_activate_base false

This ensures that new shells remain environment-neutral, only switching to conda environments upon explicit request, which some find preferable.

Channel Priority and Mirror Switching

If the default primary channel is slow or blocked, switching to an alternative mirror or adjusting channel orders can help:

conda config --set channel_priority strict

Choosing strict is beneficial when exact package versions are critical, while flexible is best for solving intricate environment constraints. Reflecting on your usage patterns helps to decide the best priority approach.

Using a Proxy

In enterprise or corporate environments, proxy settings might be necessary. Pass proxy details to conda:

conda config --set proxy_servers.http http://proxy.example.com:8080
conda config --set proxy_servers.https https://proxy.example.com:8080

Adjust them according to local network policies. This ensures smooth downloads of packages even behind strict firewalls.

Troubleshooting

Even with robust defaults, issues can arise in specialized contexts or after major OS updates. Proper diagnosis often involves reviewing error messages and trying known fixes. Below are common pitfalls and their resolutions:

Installation Failures

If the installer stops prematurely, verify that the downloaded script is intact. Re-download if the sha256sum check fails. Also confirm that the installation path is write-accessible. If an access denied error appears, run the bash script either under a user with sufficient privileges or specify a user path within /home.

Path Conflicts

Occasionally, multiple Python or conda versions can cause path-related confusion. Inspect the environment variables:

echo $PATH

Ensure that the new conda installation path precedes any other Python path. Adjust the ~/.bashrc file to move conda’s lines above conflicting statements if needed.

Security Policy Warnings

Some cryptographic libraries rely on SHA1 usage, potentially disabled by strict security policies. If the system complains about an unsupported algorithm, reconfigure the crypto policy or switch to channels or packages that only use modern checksums.

Solving Environment Issues

When conda tries to resolve complex dependencies and fails, it may print Found conflicts! Looking for incompatible packages.. This can happen with large or intricate environment definitions. Possible solutions:

  • Use conda config --set channel_priority flexible to relax constraints.
  • Remove rarely used channels from conda config to reduce package conflicts.
  • Upgrade conda with conda update conda if possible, as newer versions often improve dependency resolution.

Repairing a Corrupted conda Installation

Occasionally, mixing incompatible repositories or forcibly upgrading Python can damage the base environment. Reinstalling Miniconda with the --force flag overwrites files in place:

bash Miniconda3-latest-Linux-x86_64.sh -f

This process fixes broken base environment packages without duplicating directories.

Best Practices

A few extra steps ensure performance, maintain system tidiness, and preserve stable environments for mission-critical applications. Thoughtful organization of conda environments, routine updates, and security awareness all strengthen reliability.

Security Considerations

Limiting root-level actions prevents accidental system file corruption. Installing Miniconda under a normal user’s home directory is standard practice. If you need system-wide availability, ensure that no untrusted scripts modify critical environment variables. Regularly updating packages also helps patch discovered vulnerabilities in Python libraries.

Performance Optimization

Miniconda can run resource-intensive data analysis tasks. Performance in such tasks primarily depends on CPU, memory, and specialized hardware like GPUs. However, environment-level performance can be enhanced by cleaning unneeded caches:

conda clean --all

This removes unused package tarballs and index caches, keeping disk usage in check.

Backup Procedures

Critical Python environments usually house unique combinations of library versions. Export environment configurations with:

conda env export --name myenv > myenv.yml

Store this YAML file in version control or backups. If reinstallation is needed, replicate the environment using:

conda env create -f myenv.yml

This fosters consistency across multiple machines or attempts over time.

Update Management

Conda includes robust update mechanics to keep installed packages at desired versions. Plain updates for a single environment:

conda update --all

A more controlled approach is specifying the package:

conda update numpy

This method updates numpy without affecting unrelated packages. Coupled with pinned package versions, precise reproducibility is maintained.

Congratulations! You have successfully installed Miniconda. Thanks for using this tutorial for installing the Miniconda on your Rocky Linux 9 system. For additional or useful information, we recommend you check the official Miniconda website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button