Category Archives: Ubuntu

MongoDB: Recover Data after an Unexpected Shutdown in Ubuntu

Note: MongoDBs data files are usually located at /data/db but in my Ubuntu installation they where in /var/lib/mongodb.

Repair preserving data:

sudo mkdir /var/lib/mongodb0
sudo mongod --dbpath /var/lib/mongodb --repair --repairpath /var/lib/mongodb0
sudo mongod --dbpath /var/lib/mongodb0

Now that the server is up with a repaired version (/var/lib/mongodb0) of your original data (from /var/lib/mongodb) use mongo client to verify that everything is OK. In that case replace /var/lib/mongodb with /var/lib/mongodb0.

sudo rm -rf /var/lib/mongodb
sudo mv /var/lib/mongodb0 /var/lib/mongodb
sudo chown -R mongodb:mongodb /var/lib/mongodb

Repair without preserving data:

sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --dbpath /var/lib/mongodb --repair

When this completes, the repaired data files will replace the original data files in the /var/lib/mongodb directory.

Ref: http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/

Install MongoDB in Ubuntu 12.04 with PHP driver

Install MongoDB:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install mongodb-10gen

Install MongoDB PHP driver:

sudo apt-get install php-pear php5-dev
pecl search mongo
sudo pecl install mongo

Configure MongoDB PHP driver: Create a file called /etc/php5/conf.d/mongo.ini with this content:

extension=mongo.so

Then restart Apache:

sudo service apache2 restart

Start, stop and restart MongoDB:

sudo service mongodb start
sudo service mongodb stop
sudo service mongodb restart

Configuration file:

/etc/mongodb.conf

Log file:

/var/log/mongodb/mongodb.log

Data files:

/var/lib/mongodb

Ref: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

Select different available java and javac versions in Ubuntu with update-alternatives

It’s possible to have more than one version of Java in the same machine.

If you have more than one Java JRE or JDK installed you can switch between them with the update-alternatives command:

$ sudo /usr/sbin/update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                           Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1051      manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java to provide /usr/bin/java (java) in manual mode.

You can do just the same for javac:

$ sudo /usr/sbin/update-alternatives --config javac

There are 2 choices for the alternative javac (providing /usr/bin/javac).

  Selection    Path                                        Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk-i386/bin/javac   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-i386/bin/javac   1061      manual mode
  2            /usr/lib/jvm/java-7-openjdk-i386/bin/javac   1051      manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-7-openjdk-i386/bin/javac to provide /usr/bin/javac (javac) in manual mode.

You can check wich version is currently in use running:

$ java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2)
OpenJDK Server VM (build 23.7-b01, mixed mode)
$ javac -version
javac 1.7.0_25

Find the library or program that installs a specific file with apt-file

Sometime you could end up in a situation where you need to know which program or library installs a file. That happened to me while installing redmine. I got an error telling me that it couldn’t find the MagickWand.h file. apt-file tells you the library you need to install to get that file.

$ sudo apt-get install apt-file
$ sudo apt-file update
$ apt-file search MagickWand.h
imagemagick-doc: /usr/share/doc/imagemagick/www/api/MagickWand/struct__MagickWand.html
libmagickwand-dev: /usr/include/ImageMagick/wand/MagickWand.h

Thus I installed libmagickwand-dev and the problem went away:

sudo apt-get install libmagickwand-dev

How to install Google Chrome in Ubuntu

First add the signing key and the repository:

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update

Then to install the stable release:

sudo apt-get install google-chrome-stable

If you want to instal the unstable release:

sudo apt-get install google-chrome-unstable

And for the beta version:

sudo apt-get install google-chrome-beta

To uninstall Chromium:

sudo apt-get remove chromium-browser

Source: http://www.howopensource.com/2011/10/install-google-chrome-in-ubuntu-11-10-11-04-10-10-10-04/

  • Page 1 of 5
  • 1
  • 2
  • 3
  • 4
  • 5
  • >