Installing Metasploit framework on Ubuntu Server 16.04 LTS

Installing oracle Java:
  sudo add-apt-repository -y ppa:webupd8team/java  
  sudo apt-get update  
  sudo apt-get -y install oracle-java8-installer   

Installing Dependencies:

But before that update and upgrade your system
  sudo apt-get update  
  sudo apt-get upgrade  
now paste the below command on your terminal
 sudo apt-get install build-essential libreadline-dev libssl-dev libpq5 libpq-dev libreadline5 libsqlite3-dev libpcap-dev git-core autoconf postgresql pgadmin3 curl zlib1g-dev libxml2-dev libxslt1-dev vncviewer libyaml-dev curl zlib1g-dev  
Installing Ruby:
 sudo apt-get install gnupg2  
 curl -sSL | gpg2 --import -  
 curl -L | bash -s stable  
 source ~/.rvm/scripts/rvm  
 echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc  
 source ~/.bashrc  
 RUBYVERSION=$(wget -q -O - )  
 rvm install $RUBYVERSION  
 rvm use $RUBYVERSION --default  
 ruby -v   
Installing Nmap:
 mkdir ~/Development  
 cd ~/Development  
 git clone  
 cd nmap  
 sudo make install  
 make clean  
Configure Postgre SQL Server:
 sudo su  
 su postgres   
Now we need to create user and database in postgresql for metasploit. First create a user 'msf'
 createuser msf -P -S -R -D 
now we create a database 'msf'
 createdb -O msf msf
after that type 'exit' command twice
 postgres@Test:/home/ajay$ exit
 root@Test:/home/ajay# exit
now our postgres db credentials are

Password : 12345 (postgres password)
username : msf
dbname : msf

Installing Metasploit Framework:

 cd /opt
 sudo git clone
 cd metasploit-framework
 rvm --default use ruby-${RUBYVERSION}@metasploit-framework
 gem install bundler
 bundle install
 sudo bash -c 'for MSF in $(ls msf*); do ln -s /opt/metasploit-framework/$MSF /usr/local/bin/$MSF;done'
Creating and configuring database.yml file:
create a file database.yml at '/opt/metasploit-framework/config/' directory and put the below content in it
 adapter: postgresql
 database: msf
 username: msf
 password: 12345
 port: 5432
 pool: 75
 timeout: 5
sudo vi /opt/metasploit-framework/config/database.yml

put the above content and save the file. Now we need to create environment variable so it is loaded by msfconsole
 sudo sh -c "echo export MSF_DATABASE_CONFIG=/opt/metasploit-framework/config/database.yml >> /etc/profile"
 source /etc/profile
and thats it. Now start ssh session with your ubuntu server and type 'msfconsole'