# How to Remove Previously Installed MongoDB Versions Using m

> Easily remove old MongoDB versions with m rm <version>. Clean up your installations efficiently and manage your MongoDB environments like a pro. Learn how now.

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

---

**To remove previously installed MongoDB versions using m, run `m rm <version>` which deletes the version directory from `$HOME/.local/m/versions/` and warns if removing the active version.**

The **m** CLI tool is a popular MongoDB version manager that installs server binaries, tools, and shells under `$HOME/.local/m`. When you need to clean up disk space or remove outdated releases, understanding how to remove previously installed MongoDB versions using m ensures you don't accidentally delete your active instance. This guide explains the internal mechanics of the removal process based on the aheckmann/m source code.

## Understanding the m rm Command

The `m rm` command serves as the primary interface for deleting MongoDB installations managed by the tool. According to the argument-handling logic in `bin/m` (lines 1910-1912), when you invoke `m rm`, the script shifts arguments and dispatches to the `remove_versions` function:

```bash
rm) shift; remove_versions $@; exit ;;

```

All installed versions reside in `$VERSIONS_DIR` (typically `$HOME/.local/m/versions/`), with each release occupying its own subdirectory named after the version number.

## Internals of the remove_versions Function

The `remove_versions` function (defined around lines 1443-1470 in `bin/m`) handles the actual deletion logic through several distinct phases.

### Argument Validation

The function first verifies that you provided at least one version argument. If `$1` is empty, it calls `abort` with the message "version(s) required", preventing accidental invocations.

### Active Version Detection

Before deletion begins, `remove_versions` calls `check_current_version` to identify which MongoDB version is currently symlinked into `$M_BIN_DIR`. This value is stored in the `$active` variable, allowing the script to detect if you're attempting to remove the version you're currently using.

### Removal Process and Confirmation

For each version argument passed, the function performs these steps:

- **Active version warning**: If the target matches `$active`, the script prints a warning and prompts for confirmation (unless disabled).
- **Directory deletion**: The script removes `$VERSIONS_DIR/$version` recursively using `rm -rf`.
- **Cache clearing**: After removal, `$active` is cleared to prevent subsequent commands from referencing the deleted version.

The confirmation behavior is controlled by the `M_CONFIRM` environment variable. When set to `1` (default), you receive an interactive prompt before deleting the active version. Set `M_CONFIRM=0` to bypass confirmation, which is how the `m reinstall` command operates internally.

### Handling Non-existent Versions

If the target directory doesn't exist in `$VERSIONS_DIR`, the function outputs "MongoDB version $version is not installed" and continues processing remaining arguments rather than failing.

## Practical Code Examples

### Remove a Single Version

Delete a specific MongoDB release:

```bash
m rm 6.0.13

```

If 6.0.13 is your active version, you'll see a warning and confirmation prompt.

### Remove Multiple Versions

Pass multiple arguments to clean up several releases at once:

```bash
m rm 5.0.12 5.0.13 5.0.14

```

The `while` loop in `remove_versions` processes each version sequentially.

### Force Removal Without Confirmation

Skip the safety prompt when removing the active version:

```bash
M_CONFIRM=0 m rm 6.0.13

```

This immediately deletes the version directory without interactive confirmation.

### Reinstall a Version

The `reinstall` shortcut combines removal and installation:

```bash
m reinstall 6.0.13

```

Internally, this sets `CONFIRM=0`, invokes `remove_versions`, then calls `install_mongo` to download and install the version again.

## Summary

- **m** installs MongoDB versions under `$HOME/.local/m/versions/`.
- Use `m rm <version>` to delete specific releases via the `remove_versions` function in `bin/m`.
- The command warns before removing the active version unless `M_CONFIRM=0` is set.
- Multiple versions can be removed in a single command by passing additional arguments.
- The `m reinstall` command reuses the same removal logic with confirmation disabled.

## Frequently Asked Questions

### Where does m store installed MongoDB versions?

m stores all downloaded MongoDB binaries in `$HOME/.local/m/versions/` (referenced internally as `$VERSIONS_DIR`), with each version residing in its own subdirectory.

### Will m rm delete my data files?

No. The `remove_versions` function only deletes the MongoDB binary directory (`$VERSIONS_DIR/$version`). It does not touch your database data files, configuration files, or logs stored elsewhere on your system.

### How do I remove the currently active MongoDB version?

Run `m rm <version>` with the active version number. You will receive a warning and confirmation prompt unless you set `M_CONFIRM=0` beforehand. Alternatively, use `m use <different-version>` to switch versions before removal.

### Can I recover a version after running m rm?

No. The removal uses `rm -rf` to permanently delete the version directory. If you need the version again, you must reinstall it using `m install <version>` or `m reinstall <version>`.