# How to List All Installed MongoDB Versions Managed by m

> Easily list all installed MongoDB versions managed by m. Run m or m installed to see your downloaded versions and identify the active one.

- Repository: [Aaron Heckmann/m](https://github.com/aheckmann/m)
- Tags: how-to-guide
- Published: 2026-02-23

---

**Run `m` without arguments or use `m installed` (alias `m lls`) to display all downloaded MongoDB versions, with an asterisk marking the currently active version.**

The `m` MongoDB version manager by **aheckmann/m** stores every downloaded binary in a local versions directory. When you need to see which releases are available locally or verify which one is currently active, the tool provides multiple ways to list all installed MongoDB versions managed by `m`.

## Default Command (No Arguments)

When you invoke `m` without any sub-commands, the script automatically calls the `display_versions` function defined in `bin/m` (lines 96-99). This function scans the `VERSIONS_DIR` directory—defaulting to `$HOME/.local/m/versions`—and prints each discovered version.

The active version (the one linked to your `PATH`) is marked with an asterisk (`*`).

```bash
$ m
    7.0.14
  * 8.0.6

```

## Explicit Sub-Commands

For clarity in scripts or documentation, `m` provides explicit commands that invoke the same listing logic.

### Using the installed Command

The `installed` sub-command triggers the `display_versions` function (handled at line 1903 in `bin/m`). This produces identical output to running `m` alone.

```bash
$ m installed
    7.0.14
  * 8.0.6

```

### Using the lls Alias

`lls` is a shorthand alias for `installed`, also processed at line 1903. This is useful for quick terminal interactions.

```bash
$ m lls
    7.0.14
  * 8.0.6

```

## JSON Output for Automation

When integrating with CI/CD pipelines or configuration management tools, human-readable output is insufficient. The `display_versions` function (lines 60-73 and 99-104 in `bin/m`) supports a `--json` flag that outputs structured data including the version name and full binary path.

```bash
$ m installed --json
[
  {
    "name" : "7.0.14",
    "path" : "/home/you/.local/m/versions/7.0.14/bin/"
  },
  {
    "name" : "8.0.6",
    "path" : "/home/you/.local/m/versions/8.0.6/bin/"
  }
]

```

## Where Versions Are Stored

Understanding the storage location helps when troubleshooting or manually cleaning old releases. By default, `m` stores downloaded MongoDB binaries in:

```

$HOME/.local/m/versions/

```

If you have defined the `M_PREFIX` environment variable, `m` uses `$M_PREFIX/m/versions` instead. The `display_versions` function (starting at line 56 in `bin/m`) dynamically determines this path before enumerating subdirectories.

## Implementation Details

The listing functionality is implemented entirely within the main Bash script at `bin/m`:

- **Argument parsing**: Lines 96-99 handle the zero-argument case by calling `display_versions`
- **Sub-command handling**: Line 1903 processes the `lls|installed` case statement
- **Core logic**: The `display_versions` function (lines 56-96) loops through `$VERSIONS_DIR`, identifies the active version by checking the current symlink (lines 80-96), and formats output accordingly

## Summary

- Run **`m`** without arguments to see all installed versions with the active one marked by an asterisk
- Use **`m installed`** or the alias **`m lls`** for explicit, script-friendly commands
- Append **`--json`** to any listing command for machine-readable output including full binary paths
- Versions reside in **`$HOME/.local/m/versions`** by default, or under **`$M_PREFIX/m/versions`** if the prefix environment variable is set

## Frequently Asked Questions

### How do I know which MongoDB version is currently active?

The active version is indicated by an asterisk (`*`) to the left of the version number when you run `m`, `m installed`, or `m lls`. This marker corresponds to the binary currently linked in your system `PATH` according to the `display_versions` function in `bin/m` (lines 80-96).

### Can I change the directory where m stores MongoDB versions?

Yes. Set the `M_PREFIX` environment variable to your desired base directory. `m` will then use `$M_PREFIX/m/versions` instead of the default `$HOME/.local/m/versions`. Ensure this variable is exported before running any `m` commands.

### Is there a way to list installed versions in a format suitable for scripts?

Yes. Use the `--json` flag with any listing command, such as `m installed --json` or `m lls --json`. This outputs a JSON array containing objects with `name` and `path` keys, making it ideal for parsing with tools like `jq` or for use in automated deployment scripts.

### What happens if I run m without any arguments?

Running `m` with no arguments defaults to the `display_versions` function (lines 96-99 in `bin/m`), which lists all installed MongoDB versions and highlights the active one. This is functionally identical to running `m installed` or `m lls`.