TECH / Servers & Websites 3 min read

How to Install mc (Midnight Commander) on Ubuntu: Fix “Unable to locate package mc”

Antonio NEMCD Author
Published Oct 2, 2019 · 3 min

On a fresh Ubuntu Server install (18.04, 20.04, 22.04, or 24.04), running sudo apt install mc often throws E: Unable to locate package mc. The reason is simple: Midnight Commander lives in the universe repository, which is frequently disabled by default on minimal server images.

Installing Midnight Commander (mc) on Ubuntu via the universe repository

Quick install (3 commands): enable the universe repository, refresh the package index, and install mc:

sudo add-apt-repository universe
sudo apt update
sudo apt install -y mc

If You Get “add-apt-repository: command not found”

On minimal VPS images and Docker containers, add-apt-repository may not be preinstalled. You have two quick ways around it:

  1. Install the helper package and rerun the command:
    sudo apt update
    sudo apt install -y software-properties-common
    sudo add-apt-repository universe
    sudo apt update && sudo apt install -y mc
  2. Enable universe manually without extra packages:
    • On Ubuntu 24.04 (Noble) and newer, sources use DEB822 format in /etc/apt/sources.list.d/ubuntu.sources. Open it with sudo nano /etc/apt/sources.list.d/ubuntu.sources and make sure universe appears on the Components: line (for example: Components: main restricted universe multiverse).
    • On Ubuntu 20.04 / 22.04, open sudo nano /etc/apt/sources.list and confirm universe is included on your deb http://archive.ubuntu.com/ubuntu ... lines.

    Save the file and run sudo apt update && sudo apt install -y mc.

Launching mc and Essential Keyboard Shortcuts

Start Midnight Commander by typing mc (or sudo mc when editing system config files). These shortcuts immediately speed up terminal work:

  • Tab – switch between the left and right panels.
  • F3 / F4 – view or edit the highlighted file.
  • F5 / F6 – copy or move/rename files and folders.
  • F7 / F8 – create a directory / delete files or folders.
  • Ctrl + O – toggle the panels out of the way to run shell commands, then switch right back without closing mc.
  • F10 – quit Midnight Commander.

Two Helpful Tweaks Right After Installing

  1. Pick your favorite F4 editor. The first time you press F4, Ubuntu asks which editor to use (nano, mcedit, vim). If you picked the wrong one, switch anytime by running select-editor (or enable the built-in mcedit under F9 → Options → Configuration → Use internal edit).
  2. Stay in the active directory on exit. By default, pressing F10 drops your shell back into the folder where you launched mc. To remain inside the directory you navigated to, add this alias to the bottom of ~/.bashrc:
    alias mc='. /usr/lib/mc/mc-wrapper.sh'

    Then reload with source ~/.bashrc.

Whenever I provision a fresh Ubuntu VPS (such as a server on Fornex with 7% off or hourly Vultr), installing mc is almost always the first thing I do right after setting up SSH key login.

Disclosure: the Fornex and Vultr links are affiliate links – your price stays standard or discounted, while the blog earns a small commission.

Once universe is enabled, Midnight Commander installs in ten seconds on any Ubuntu box and saves tons of time browsing configs and logs.

Related posts:

Leave a Comment