Installing Mermaid CLI on Ubuntu VM

A Step-by-Step Guide to Setting Up Mermaid CLI on an Ubuntu Virtual Machine

·

2 min read

Make sure to pick x86-64 VM as Puppeteer, which mermaid-cli is dependent on, is not available for ARM processors. (Reference)

Dependencies

To successfully run Mermaid CLI, you need to install several dependencies that Puppeteer relies on. Execute the following command to install all the necessary packages:

sudo apt install ca-certificates fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils

These libraries ensure that Puppeteer can function correctly on your Ubuntu VM, providing the necessary graphical and system support.

Install Node.js and npm

To manage Node.js versions efficiently, it's recommended to use the Node Version Manager (NVM). This tool allows you to install multiple versions of Node.js and switch between them effortlessly.

As the application user, follow the instructions to install NVM from its GitHub repository. You can typically install NVM by running:

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Once NVM is installed, load it into your shell session:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Use NVM to install the latest version of Node.js:

nvm install node

Install Mermaid CLI

After setting up Node.js, you can proceed to install Mermaid CLI globally using npm. This tool allows you to convert Mermaid diagrams into images and other formats directly from the command line.

Run the following command to install Mermaid CLI:

npm install -g @mermaid-js/mermaid-cli

By following these steps, you will have a fully functional setup of Mermaid CLI on your Ubuntu VM, ready to generate diagrams and visualizations as needed.