Installing Metasploit in Ubuntu 18.04

How To Install Metasploit Framework Ubuntu 18.04


The Metasploit Framework is an integral component to every penetration testers tool-kit. This guide will teach you how to install Metasploit Framework in Ubuntu 18.04. You will also install and configure RVM and Postgres.
For additional information and troubleshooting tips please checkout some of the links in the related content section at the bottom of this tutorial.

Install Metasploit Dependencies

The following is a list of dependencies can also be found on the Rapid7 Github page Setting Up a Metasploit Development Environment

sudo apt-get install gpgv2 autoconf bison build-essential curl git-core libapr1 libaprutil1 libcurl4-openssl-dev libgmp3-dev libpcap-dev libpq-dev libreadline6-dev libsqlite3-dev libssl-dev libsvn1 libtool libxml2 libxml2-dev libxslt-dev libyaml-dev locate ncurses-dev openssl postgresql postgresql-contrib wget xsel zlib1g zlib1g-dev

Configure The Postgres Database

In order to get the most functionality after you install Metasploit Framework you will want to have the Postgres database properly configured. This allows for faster searching as well as a ton of great features for reporting and organizing your penetration testing results. Here is how to setup your Postgres database afre you install Metasploit Framework.

Switch to the postgres user account

sudo su postgres

Create a postgres role for Metasploit

createuser msfuser -S -R -P

Create the database

createdb msfdb -O msfuser

Exit from the postgres user account


Enable Postgres to start automatically

sudo update-rc.d postgresql enable

Install & Configure RVM

RVM is recommended by Rapid7 for manually installing Metasploit Framework. The following steps should be all you need to get up and running. Checkout the official RVM documentation for additional information and troubleshooting help.

Install the public keys

gpg --keyserver hkp:// --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Install RVM

\curl -sSL | bash -s stable --ruby

Source The RVM Scripts

source ~/.rvm/scripts/rvm

Download & Install Metasploit Framework

Checkout the latest source repository from Github.

git clone

Change into the new directory.

cd metasploit-framework/

Install the necessary version of Ruby.

rvm --install .ruby-version

Install The Bundler Gem

gem install bundler

Install the necessary Ruby Gems.

bundle install

Start Metasploit


Configuring Metasploit & Postgres

create a file called “database.yml” within the “~/.msf4/” directory and paste in the contents below. Make sure to edit your password appropriately.

# Development Database
development: &pgsql
  adapter: postgresql
  database: msfdb
  username: msfuser
  password: [PASSWORD]
  host: localhost
  port: 5432
  pool: 5
  timeout: 5

# Production database -- same as dev
production: &production
  <<: *pgsql

# Test database -- not the same, since it gets dropped all the time
  <<: *pgsql
  database: msfdb

Hopefully everything went smoothly for you and you should now be up and running with Metasploit Framework in Ubuntu 18.04. If you ran into any trouble following this guide please check out some of the additional references below. If all else fails, feel free to ask a question in the comment section.

Install Metasploit Framework Additional References

Share this article

  • This piece of article is good for installing Metasploit-Framework in Linux distro. But hacking is not limited to PC only , if you want to install metasploit on Android and hack another android using metasploit just check out our article at ->

  • Still a good guide after all these years

  • This article is very useful. It helped me a lot

  • Well done sir.

    One of the very few guides that worked well.

    Installed on Debian 9 – Stretch

  • I am unable to paste into ubuntu, do you know how to make this feature available? Ive tried multiple suggestions from just googling “how to paste into ubuntu” and none work. Any ideas? Thank you for this article.

    • If you are trying to paste into a Terminal you will need to pres “Ctrl+Shift+V” to paste.

  • ./msfconsole
    Could not find rake-12.1.0 in any of the sources
    Run `bundle install` to install missing gems.

  • Hi,
    Do you have a general article about Red Team, blue Team and Hunt team at a penetration test?
    In Germany I found that
    Thank you for your reply

  • I’m getting this error message when trying to run msfconsole: (at master@1f64463) is not yet checked out. Run `bundle install` first.

    but when i run bundle install I get:
    Bundle complete! 18 Gemfile dependencies, 132 gems now installed.
    Use `bundle show [gemname]` to see where a bundled gem is installed.

    Also I am unable to locate the “~/.msf4/” directory

    • Hey Ryan, thanks for your comment. I just ran a

      git pull

      to update to the latest code and when trying to run msfconsole I got the exact error you mentioned. (at master@1f64463) is not yet checked out. Run `bundle install` first.

      However for me running

      bundle install

      resolved the issue.

      Also the ./msf4 directory doesn’t exist until you run msfconsole for the first time. Checkout this video tutorial for additional information.

  • Metasploit Tutorial From Basic To Advance,Fast Track Hacking Tutorial,Fast-Track Mass Client-Side Attack,Nessus With Metasploit Tutorial,Integrate Nessus With Metasploit,Metasploit Remote Desktop Exploit,Metasploit Autopwn With Nessus,Social Engineering toolkit

  • awesome article bro thanks

  • Nice tutorial. one command I found out about last year was “msfdb init”. this automates creating the msf db and user, adding config and sets msf to use the newly created yaml. you still have to install and start postgresql first.

    • Thanks for sharing, thats a great shortcut! I’m just a control freak so I like to do everything manually ;-)

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Share This

    Recent Posts

    Subscribe To Our Mailing List

    The Ultimate Burp Suite Training Program

    Learn Network Penetration Testing

    Penetration Testing



    Web Application Hacking

    Copyright 2024


    Are You Using the Top 5 Pentest Tools?

    Enter your email address to download your copy of our FREE e-book and find out now!

    Thank you, now go check your email!!