Last Updated: February 25, 2016
· zshamrock

Install different versions of mongo locally linux

This script helps you to configure mongodb alternatives for different version of mongodb installed on your local linux machine. The trick here is to use --slave which allows you to switch between mongo groups (in my case 2.2.2 and 2.4.0 versions), so after alternatives are added you can switch all you mongo binaries easily using sudo update-alternatives --config mongo:

# run: ./ 0|1 <priority>    
files=(bsondump mongod  mongodump  mongoexport  mongofiles  mongoimport  mongooplog  mongoperf  mongorestore  mongos  mongosniff  mongostat  mongotop)
locations=("$HOME/tools/nosql/mongodb/mongodb-linux-i686-2.2.2/bin" "$HOME/tools/nosql/mongodb/mongodb-linux-i686-2.4.0/bin")
mkdir -p "${link}"
install_command="update-alternatives --install ${link}/mongo mongo ${location}/mongo ${priority}"
for file in "${files[@]}"
    install_command="${install_command} --slave ${link}/${file} ${file} ${location}/${file}"
echo on
`sudo ${install_command}`

You should edit your mongodb locations first. After done, you can run:

  • ./ 0 10
  • ./ 1 5

where the 1st parameter is the index of you location in locations array, and the 2nd parameter is the priority.