Managing Multiple Node.js, PHP, and MariaDB Versions: Fedora’s DNF Modularity “Secret Weapon”

Fedora tutorial - IT technology blog
Fedora tutorial - IT technology blog

Context: When Old and New Projects “Clash” Over Versions

Whether you’re in Web Development or DevOps, you’ve likely faced the headache of an old project stuck on PHP 7.4 while a new one requires PHP 8.2. Node.js is no different, with each app demanding its own environment. Usually, we turn to nvm or third-party repositories, which carry risks of system conflicts.

I’ve used Fedora as my primary workstation for two years now. What impresses me most is DNF Modularity. Instead of forcing a single software version, Modularity allows the system to run multiple version “streams” directly from the official repositories.

Why not just use Docker? In reality, Modularity provides absolute stability because it’s deeply integrated into dnf. You won’t have to worry about security or library errors during upgrades. In just 3-5 minutes, you can jump from Node.js 18 to 20 without breaking OS dependencies.

Quick Understanding of Modules, Streams, and Profiles

Before typing commands, let’s look at these three core concepts to avoid confusion:

  • Module: The name of the software you want to manage (e.g., nodejs).
  • Stream: The specific version of that module (e.g., 18, 20, 22).
  • Profile: The installation type suited to your needs. You can choose common for servers or development for extra debugging tools.

Want to see what’s available on your machine? Use this command:

dnf module list

The returned list is often very long. To filter quickly, for example for Node.js, run:

dnf module list nodejs

Pay attention to the Stream column. The [d] character indicates the default version, while [i] signals that the version is already installed on your system.

Hands-on: Flexible Version Switching in an Instant

1. Handling Node.js

Suppose you’re on Node.js 18 but a client requires Node.js 20. Forget downloading scripts from nodesource; the standard procedure is “Reset – Enable – Install”:

# Step 1: Reset module to clear old configurations
sudo dnf module reset nodejs

# Step 2: Enable the version 20 stream
sudo dnf module enable nodejs:20

# Step 3: Install or synchronize the system
sudo dnf install nodejs

If Node.js 18 is already installed, you just need to run sudo dnf distro-sync. The system will automatically upgrade or downgrade related packages for synchronization.

2. Managing PHP for Web Projects

PHP is where Modularity truly shines. To install a clean PHP 8.2 for a server, I usually use a Profile:

sudo dnf module enable php:8.2

# Install using the 'common' profile to get all frequently used extensions
sudo dnf install @php:8.2/common

The @ character allows you to install a whole set of packages without having to remember individual library names. This saves significant time compared to typing php-mbstring, php-xml, etc.

3. With MariaDB: Caution is Key

Switching database versions is always riskier due to the underlying data structure. The activation method remains the same:

sudo dnf module enable mariadb:10.11
sudo dnf install mariadb-server

Hard-earned lesson: DNF only upgrades the software (binary); it doesn’t automatically run mysql_upgrade for you. Always mysqldump your data before changing streams to avoid disastrous consequences.

Verification and Rolling Back When Errors Occur

Once finished, don’t forget to verify the results. The following command lists all active modules:

dnf module list --enabled

Check the version directly to be sure:

node -v && php -v

Accidentally enabled the wrong stream and broke your environment? Don’t panic. DNF has a great history feature. Just run:

dnf history

Find the ID of the faulty operation and type dnf history undo <ID> to revert to the previous state in seconds. This is the lifesaver I frequently use when I tinker a bit too much.

DNF Modularity turns Fedora into a versatile machine, keeping the system clean while meeting every demanding project requirement. Have a smooth experience!

Share: