How to Skip Confirmation Prompts When Installing MongoDB Versions with m
Set the environment variable M_CONFIRM=0 before running the command to bypass all confirmation prompts when installing MongoDB binaries.
The m version manager for MongoDB provides a simple way to switch between database versions, but by default it prompts for confirmation before downloading binaries. According to the source code in aheckmann/m, this interactive behavior is controlled by a specific configuration variable that you can override for automated or non-interactive environments.
How the Confirmation Prompt Works in m
The confirmation logic resides in the core executable bin/m. At line 36, the script defines a CONFIRM variable that defaults to interactive mode:
CONFIRM=${M_CONFIRM:-1} # default is to ask (line 36)
The prompt_install() function (lines 25-35) checks this variable before displaying the interactive prompt:
prompt_install() {
if [[ "$CONFIRM" == 1 ]]; then # only ask when CONFIRM is 1
# ... prompt logic ...
fi
}
When CONFIRM evaluates to 1, the function pauses execution and waits for user input. When set to 0, the function skips the prompt entirely and proceeds with the installation.
Methods to Skip Confirmation Prompts
You have two reliable approaches to disable these prompts, depending on whether you prefer environment variables or shell piping.
Set the M_CONFIRM Environment Variable (Recommended)
The most robust method uses the M_CONFIRM environment variable. Because the script uses the syntax ${M_CONFIRM:-1}, setting this variable to 0 forces CONFIRM to 0, bypassing the interactive check without spawning additional processes.
# Single command execution
M_CONFIRM=0 m 7.0
# Persistent for the current shell session
export M_CONFIRM=0
m 6.0.13
m tools stable
This approach is preferred for automation scripts and CI/CD pipelines because it explicitly signals intent to the application and works across all m subcommands that trigger downloads. The test suite in test/suite.mjs demonstrates this pattern by setting M_CONFIRM: '0' to ensure non-interactive test execution.
Pipe yes to the Command
Alternatively, you can pipe the yes command to automatically answer the prompt. This method is documented in the project's README.md and works by feeding an automatic "yes" response to the prompt_install function.
yes | m 7.0
While effective for one-off commands, this creates an extra process and is less explicit than the environment variable method.
Code Examples for Automated Workflows
For scripts that install multiple versions or set up development environments, combine the environment variable with version specifications:
# Install multiple versions non-interactively
export M_CONFIRM=0
m 7.0.5
m 6.0.13
m 4.4.29
# Install enterprise edition without prompts
M_CONFIRM=0 m 7.0-ent
Summary
- The confirmation prompt in
mis controlled by theCONFIRMvariable defined inbin/mat line 36. - Set
M_CONFIRM=0to disable prompts cleanly using the built-in environment variable check. - Use
yes | mas a quick alternative for single commands, though it spawns an extra process. - Both methods work with all
msubcommands, includingtools,shell, and enterprise edition installations.
Frequently Asked Questions
Does skipping confirmation affect which MongoDB version gets installed?
No. Setting M_CONFIRM=0 or using yes | m only bypasses the download confirmation prompt. The version resolution logic remains unchanged, and m will still install the exact version specified (e.g., m 7.0 installs the latest 7.0.x release).
Can I permanently disable confirmation prompts for all m commands?
Yes. Add export M_CONFIRM=0 to your shell configuration file (such as ~/.bashrc, ~/.zshrc, or ~/.bash_profile). This persists the setting across all terminal sessions, making every m command non-interactive by default.
Why does m ask for confirmation before downloading?
The prompt_install() function in bin/m (lines 25-35) requires confirmation to prevent accidental downloads of large binaries and to ensure users intentionally want to install the specific MongoDB version, particularly in production or resource-constrained environments.
Will M_CONFIRM=0 work with m tools and enterprise editions?
Yes. The CONFIRM variable is checked globally in the bin/m script, so setting M_CONFIRM=0 suppresses prompts for all operations that trigger the prompt_install() function, including tool installations (m tools stable) and enterprise builds (m 7.0-ent).
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →