To install Metasploit Framework on Ubuntu Linux, the official method is to use the Nightly Installer script from Rapid7, which sets up the framework along with its dependencies and a PostgreSQL database. Alternatively, you can install it via the system package manager or use the open-source-only version from GitHub, depending on whether you need the full community edition with its built-in web interface and database integration. This guide walks through the main installation paths, what each one gives you, and how to verify the installation works.
What Is Metasploit Framework?
Metasploit Framework is an open-source penetration testing platform that provides a unified interface for developing, testing, and executing exploits against target systems. It includes a large database of known vulnerabilities, a collection of payloads (code that runs on a compromised system), and tools for post-exploitation tasks like privilege escalation and persistence. Security professionals use it for authorized penetration tests, vulnerability research, and defensive training. The framework is written in Ruby and is modular, so users can write their own exploits or import modules from the community.
Prerequisites Before You Install
Before installing, make sure your Ubuntu system meets the basic requirements. You need a 64-bit architecture (most modern systems), at least 4 GB of RAM (8 GB is more comfortable), and about 2 GB of free disk space for the framework plus its dependencies. You also need a user account with sudo privileges because the installer writes to system directories and sets up a database service. Outdated Ruby versions can cause issues, so it’s wise to update your system first:
- Open a terminal (Ctrl+Alt+T).
- Run
sudo apt updateto refresh package lists. - Run
sudo apt upgradeto update installed packages. - Install curl and wget if they are not present:
sudo apt install curl wget.
These steps are not strictly required but they prevent common dependency conflicts.
Method 1: Official Nightly Installer (Recommended)
Rapid7 provides a script that downloads and installs the latest Metasploit Framework, including the msfconsole command-line interface, the msfdb database helper, and the necessary Ruby gems. This is the simplest way to get a working installation with the full community features.
- Download the installer script:
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall - Make it executable:
chmod +x msfinstall - Run it with sudo:
sudo ./msfinstall
The script will add the Rapid7 apt repository, install the metasploit-framework package, and set up the PostgreSQL database. After installation, you can start the database service with sudo systemctl start postgresql (if it isn’t already running) and then initialize the database with sudo msfdb init. Finally, launch the console with msfconsole. The first launch may take a minute as it loads all modules.
Method 2: Install from Ubuntu’s Repositories
Ubuntu’s official repositories include a version of Metasploit, but it is often outdated and lacks the database integration. To install it, simply run:
sudo apt update
sudo apt install metasploit-framework
This installs the msfconsole binary, but you will not get the msfdb helper or the web interface. The version may be several releases behind the latest, which means you might miss recent exploit modules and bug fixes. This method is acceptable if you only need the core console for basic tasks and do not mind an older version. However, for professional work, the nightly installer is strongly preferred.
Method 3: Install from Source (GitHub)
For developers or those who want the absolute latest code, you can clone the repository and run the framework directly from source. This requires manual dependency management and is more complex.
- Install dependencies:
sudo apt install git autoconf build-essential libpcap-dev libpq-dev zlib1g-dev libsqlite3-dev - Clone the repository:
git clone https://github.com/rapid7/metasploit-framework.git - Enter the directory:
cd metasploit-framework - Install bundler:
gem install bundler - Install Ruby gems:
bundle install - Run the console:
./msfconsole
This method gives you the bleeding edge, but you must manually update the repository with git pull and re-run bundle install whenever dependencies change. It also does not include the database setup, so you would need to configure PostgreSQL separately.
Common Installation Problems and Fixes
Several issues can arise during installation. Here are the most frequent ones and how to resolve them:
- PostgreSQL not starting: After running
msfdb init, you may get a connection error. Ensure PostgreSQL is running withsudo systemctl status postgresql. If it is inactive, start it withsudo systemctl start postgresqland enable it at boot withsudo systemctl enable postgresql. - Ruby version errors: Metasploit requires Ruby 2.7 or higher. Check with
ruby -v. If your system has an older version, install a newer one usingsudo apt install ruby-fullor use a version manager like rbenv. - Permission denied when running msfconsole: If you installed via the nightly script, the binary is in
/usr/bin/msfconsoleand should be executable. If you get a permission error, try running withsudoor check the file permissions withls -l /usr/bin/msfconsole. - Network issues during install: The installer downloads from GitHub and Rapid7’s servers. If you are behind a proxy or firewall, you may need to set environment variables like
http_proxyandhttps_proxybefore running the script. - Missing dependencies: If you see errors about missing libraries like
libpcap, install them withsudo apt install libpcap-dev.
Verifying Your Installation
After installation, you should confirm that everything works. Open a terminal and run:
msfconsole -q
This starts the console in quiet mode. You should see a banner and a prompt like msf6 >. To test the database connection, run db_status. If you see Connected to msf, the database is working. You can also check the version with version inside the console. For a quick functional test, you can search for a known module:
search eternalblue
This should return a list of modules related to the EternalBlue exploit. If you get results, the framework is properly installed and ready for use.
Safety and Legal Considerations
Metasploit is a powerful tool that can compromise systems. It is essential to use it only on systems you own or have explicit written permission to test. Unauthorized use is illegal in most jurisdictions and can result in severe penalties. When you install and run Metasploit, ensure you are in a controlled lab environment or have a signed penetration testing agreement. The framework itself is legal to install, but using it against targets without authorization is not. Always follow ethical hacking guidelines and respect privacy and property rights.
Frequently Asked Questions
Do I need PostgreSQL for Metasploit?
No, but it is highly recommended. PostgreSQL powers the database that stores your scan results, credentials, and loot. Without it, you can still use the console for basic exploitation, but you lose features like db_nmap and the ability to correlate data across sessions. The nightly installer sets up PostgreSQL automatically, while the apt version does not.
Is Metasploit free?
Yes, the Metasploit Framework is open-source and free to use. Rapid7 also offers a commercial product called Metasploit Pro, which adds a web interface, advanced automation, and reporting, but the framework itself is free and actively maintained by the community.
Can I install Metasploit on WSL (Windows Subsystem for Linux)?
Yes, you can install Metasploit on WSL2 just like on a native Ubuntu system. The nightly installer works fine, but you may need to enable systemd in WSL2 for PostgreSQL to start automatically. Alternatively, you can run the database manually with sudo service postgresql start.
Why does msfconsole take so long to start?
The console loads thousands of modules on startup, which takes time, especially on older hardware. You can speed it up by using the -q flag to suppress the banner, or by disabling the database if you do not need it. Also, ensure your system has enough RAM; 4 GB is the minimum, but 8 GB is better.
How do I update Metasploit?
If you used the nightly installer, you can update with sudo msfupdate. This script updates the framework to the latest version. For the apt version, use sudo apt update && sudo apt upgrade metasploit-framework. For a source installation, pull the latest changes with git pull and re-run bundle install.
Can I use Metasploit on other Linux distributions?
Yes, the nightly installer supports most Debian-based distributions, including Kali Linux and Debian itself. For Red Hat-based systems like Fedora, you can use the same script, but you may need to install additional dependencies manually. The framework is also available on macOS and Windows, though the installation steps differ.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Hogwarts Legacy Microsoft Visual C Runtime Error Fix
- Set Up UPI Payments Through WhatsApp
- Pair Oppo Enco Earbuds with Android, iPhone & Windows
- Fix Administrator Account Disabled Error in Windows 11
- How to Play Kodi on Smart TV from PC
- Factory Reset on Samsung Galaxy: What It Erases