# How to Run a Specific MongoDB Version Without Switching the Active Version in m

> Learn how to run a specific MongoDB version with m without changing the active version. Use the `m use <version> [args]` command for direct execution.

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

---

**Use `m use <version> [args …]` to launch a specific MongoDB binary directly without modifying the global active version symlink.**

The `m` version manager for MongoDB allows you to install multiple versions simultaneously, but switching the global active version isn't always desirable. Whether you need to test a specific release or run a temporary instance, you can execute any installed MongoDB binary directly without altering the system-wide default. According to the aheckmann/m source code, the `use` command provides this exact capability by bypassing the global symlink mechanism entirely.

## Using the `m use` Command

The `m use` command locates and executes a specific MongoDB version while leaving the active version symlink untouched. This enables side-by-side execution where you can run MongoDB 4.4 for legacy testing while keeping MongoDB 6.0 as your default active version.

### How It Works Under the Hood

In the `bin/m` script, the `execute_with_version` function handles this operation. When you run `m use`, the script constructs the path to the requested binary at `$VERSIONS_DIR/$version/bin/mongod` and executes it directly. This bypasses the `$M_BIN_DIR/mongod` symlink entirely, ensuring the global active version remains unchanged.

## Practical Code Examples

### Run a Specific Version with Custom Parameters

```bash
m use 5.0.12 --port 27018 --dbpath ./mydata

```

This starts MongoDB 5.0.12 on port 27018 without changing which version responds to the default `mongod` command.

### Background Execution for Testing

```bash
nohup m use 4.4.9 --fork --logpath ./mongod.log &

```

Run an older version in the background for compatibility testing while keeping your primary development version active.

### Alternative: Get the Binary Path

If you need the binary path for external scripts or manual execution:

```bash
BIN_PATH=$(m bin 6.2.5)
"$BIN_PATH/mongod" --port 27019 --dbpath ./otherdata

```

The `m bin` command returns the installation directory for the specified version, allowing direct invocation without the `use` wrapper.

## When to Run Specific MongoDB Versions Temporarily

Running specific versions without switching the active default is essential for:
- **Testing database migrations** across multiple MongoDB releases
- **Running integration tests** against specific server versions in CI/CD pipelines
- **Troubleshooting version-specific bugs** without disrupting your development environment
- **Supporting legacy applications** that require older MongoDB wire protocols

## Summary

- The `m use <version>` command executes a specific MongoDB binary directly without modifying global symlinks
- Implementation resides in `bin/m` within the `execute_with_version` function
- The active version symlink at `$M_BIN_DIR/mongod` remains pointed to its original target
- Use `m bin <version>` to retrieve binary paths for custom execution workflows
- All arguments passed after the version number are forwarded directly to the `mongod` process

## Frequently Asked Questions

### Does `m use` change which version is active globally?

No. The `m use` command executes the specified version temporarily without altering the global active version. The `$M_BIN_DIR/mongod` symlink continues pointing to whatever version was previously activated, meaning your default `mongod` command remains unchanged.

### Can I pass any mongod arguments to `m use`?

Yes. Any arguments you provide after the version number are passed directly to the MongoDB binary. This includes standard options like `--port`, `--dbpath`, `--fork`, `--config`, and `--logpath`, exactly as you would use them with a standard `mongod` invocation.

### What is the difference between `m use` and `m bin`?

`m use` executes the binary immediately with your provided arguments, while `m bin` simply returns the path to the version's bin directory (e.g., `$HOME/.local/m/versions/6.2.5/bin`). Use `m bin` when you need the path for external scripts, Docker configurations, or manual binary invocation outside of `m`'s execution context.

### Where does `m` store the specific version binaries?

Installed versions reside in `$VERSIONS_DIR` (typically `$HOME/.local/m/versions/<version>/bin`). The `execute_with_version` function in `bin/m` constructs this path dynamically when you invoke `m use`, locating the specific `mongod` binary without referencing the active symlink.