Magnolia CLI introduction

Magnolia CLI (latest version: Magnolia CLI latest version tag) is an npm package providing a command line interface (CLI) tool to set up and facilitate light development with Magnolia. You can use Magnolia CLI to quickly create a light module skeleton: the folders and files that form a Magnolia light module. This page provides instructions on how to install Magnolia CLI.

CLI support status

  • CLI v5 (released on October 16, 2024), is fully supported.

  • CLI v4 is in the Maintenance mode, where only security and critical issues will be addressed. Since April 16, 2025, CLI v4 will receive no further updates. After this date, you should use CLI v5.

  • CLI v2 and v3, while still available for installation through NPM, are no longer supported.

Light module minimal folder structure

Some Magnolia CLI commands may require that a minimal light module skeleton exists. For example, to run the create-app command, at least the following folder structure is expected to have been created:

<module-name>/
  └── templates
        ├── components
        └── pages

Installing Magnolia CLI

Prerequisites

Node.js

The Magnolia CLI tool runs on Node.js. To check the version of your node.js installation, run the following command in a shell:

node -v

Node.js provides two branches:

  • LTS - recommended for long-term support

  • Current - providing the latest features

Make sure you are running the latest version of the LTS branch. You can get it from Node.js downloads. It may also be installed via package managers.

Java

Having Java installed is a prerequisite if you want to use the mgnl start CLI command to start Magnolia.

Get Java

Magnolia needs at least a Java Runtime Environment (JRE) to run. Check if there’s a version of Java already installed on your computer by opening the terminal or command prompt and typing java -version. If the system reports a version number, Java is installed on your computer.

See Certified stack to confirm that the version installed is supported.

For local development, use 17.0.12-zulu. Example installation using SDKMAN:

sdk install java 17.0.12-zulu
  • Windows

  • Mac

  • Linux

On Windows, you need a Java SE Development Kit (JDK). The Java Runtime Environment (JRE) is not enough because the Tomcat application server does not recognize it.

  • JRE is for users who run Java programs on their computers.

  • JDK is for developers who write Java-based applications.

Download and install JDK. By default, JDK is installed at C:\Program Files\Java\jdk-<version>\.

Instructions

Check for JAVA_HOME

  1. Open the command prompt.

  2. Type set and press ENTER.

  3. Find JAVA_HOME in the command output and verify that the path points to your JDK installation directory, for example, C:\Program Files\Java\jdk-<version>>.xx.

  4. If JAVA_HOME is missing or it points to the wrong directory, see Set JAVA_HOME.

Set JAVA_HOME

  1. Open the Command Prompt as an administrator.

  2. Set the path for JAVA_HOME.

    setx /m JAVA_HOME "path\to\Java\jdk" (1)
    1 Where path\to\Java\jdk is where your Java Development Kit is saved.

The set command creates the JAVA_HOME environment variable and sets its value to the JDK directory. The command is executed when Magnolia starts.

For Mac, you need to download or update to Java {base-java-version} or higher. After reviewing and agreeing to the terms of the license agreement, download the file, then double-click it to launch the installation wizard and follow the installation instructions.

The installation directory varies from one Linux system to another. On Debian-based distributions, JREs or JDKs are usually installed in /usr/lib/jvm/.

Instructions

Install Magnolia CLI globally.

  • The configuration is stored globally.

  • The commands are available in the shell on all directories.

  • The global configuration can be overridden on a project level using the customize-local-config command.

The instructions that follow are based on the global npm package installation.

Which versions are available?

To display a list of released versions of Magnolia CLI, enter the following command in a shell:

npm view @magnolia/cli versions

Besides a version list, the following command shows additional information about the Magnolia CLI package:

npm view @magnolia/cli

Installing the latest version

To install the latest version (globally), run the following command in a shell:

npm install @magnolia/cli -g
Depending on your permissions and the Node.js installation location, you may have to execute the above command with root permissions. On Linux or OS-X, to run this command as root, use the following…​
sudo npm install @magnolia/cli -g

Installing a specific version

To install a specific version (globally), for example, 4.0.12, run the following command in a shell:

npm install @magnolia/cli@4.0.12 -g
Depending on your permissions and the Node.js installation location, you may have to execute the above command with root permissions. On Linux or OS-X, to run this command as root, use the following…​
sudo npm install @magnolia/cli@4.0.12 -g

Installing the latest development version

The master branch on the Magnolia NPM CLI repo typically contains the version with the latest code.

You may alternatively check out the latest code and simply install it from source.
Please be aware that the official documentation does not cover the functionalities and changes of development versions.

To install the latest version from the master, do the following after checking out the latest code:

npm pack
sudo npm install ~/dev/cli3/npm-cli/magnolia-cli-<version>.tgz -g

Updating Magnolia CLI

If you have already installed the CLI and want to update to the latest version, use:

npm update @magnolia/cli -g

Testing the installation

To test the installation, run the following command in the shell:

mgnl help

Shell autocompletion

The Magnolia CLI package provides autocompletion for bash, C-shell and Windows PowerShell.

To install/enable autocompletion, use:

mgnl tab-completion install

To uninstall it, use:

mgnl tab-completion uninstall

A successful installation of autocompletion displays a list of files to which the tab-completion script has been appended.

To test the autocompletion installation, type mgnl and then successively hit the Tab key to scroll through the available commands.

On Windows, autocompletion is only available in PowerShell. If it does not work as expected after installation, you may have to change your execution policy. To do this, in PowerShell, run as Administrator:

  Set-ExecutionPolicy RemoteSigned

Uninstalling old autocompletion source

If you have already used autocompletion with Magnolia CLI version below 2.0, you may want to uninstall the old autocompletion manually. To do so, remove the following line in your bash settings.

This is typically found at ~/.profile or ~/.bashrc from your terminal.
source /usr/local/lib/node_modules/@magnolia/cli/extra/mgnl-autocompletion.sh

v4 release history

For release notes of Magnolia CLI 4.0.0 and later releases, please see the npmjs.com/package/@magnolia/cli page.

Feedback

DX Core

×

Location

This widget lets you know where you are on the docs site.

You are currently perusing through the Magnolia CLI docs.

Main doc sections

DX Core Headless PaaS Legacy Cloud Incubator modules