Install Mago PHP Toolchain on Ubuntu 24.04

Install Mago PHP Toolchain on Ubuntu 24.04

Mago is a modern, high-performance toolchain for PHP developers, built in Rust for speed, safety, and reliability. It combines several essential code-quality tools into one streamlined workflow, helping teams maintain clean, consistent, and well-structured PHP applications. Mago includes a code formatter, linter, static analyzer, and an architectural guard. This tutorial explains how to install Mago PHP toolchain on Ubuntu 24.04.

Install Mago

First, determine the most recent Mago release available on GitHub and store the version number in a variable:

MAGO_VERSION=$(curl -s "https://api.github.com/repos/carthage-software/mago/releases/latest" | grep -Po '"tag_name": "\K[0-9.]+')

Next, download the precompiled Linux binary archive for that release:

wget -qO mago.tar.gz https://github.com/carthage-software/mago/releases/latest/download/mago-${MAGO_VERSION}-x86_64-unknown-linux-gnu.tar.gz

Create a temporary directory and extract the contents of the archive into it:

mkdir mago-temp
tar xf mago.tar.gz --strip-components=1 -C mago-temp

Move the binary into /usr/local/bin to make accessible system-wide:

sudo mv mago-temp/mago /usr/local/bin

Confirm that Mago was installed successfully by checking its version:

mago --version

Once installation is complete, remove the temporary files used during setup:

rm -rf mago.tar.gz mago-temp

Testing Mago

To see Mago in action, clone a sample PHP project. The Symfony demo application works well for this purpose:

git clone https://github.com/symfony/demo && cd demo

Initialize Mago within the project directory:

mago init

Run the linter in dry-run mode to preview suggested fixes without modifying files:

mago lint --fix --dry-run

This command analyzes the codebase and reports potential issues along with recommended improvements.

Uninstall Mago

If Mago tool is no longer needed on the system, it can be removed easily by deleting the binary from its installation path:

sudo rm -rf /usr/local/bin/mago

Leave a Comment

Cancel reply

Your email address will not be published.