sudo add-apt-repository ppa:jd-team/jdownloader sudo apt-get update sudo apt-get install jdownloader
Category Archives: Ubuntu
“AttributeError: ‘module’ object has no attribute ‘MongoClient’” error with Pymongo in Ubuntu 12.04
I’m currently doing the M101P: MongoDB for Developers online course.
I had this error while running one of the homeworks with pymongo in Ubuntu 12.04:
AttributeError: 'module' object has no attribute 'MongoClient'
I had previously installed pymongo with apt-get
like this:
sudo apt-get install python-pymongo
It looks like the package is outdated or broken so I had to remove the pymongo I had installed before and reinstall it using PiP:
sudo apt-get purge python-pymongo sudo apt-get install python-pip sudo pip install pymongo
Ref: http://stackoverflow.com/questions/17624416/cant-import-mongoclient
MongoDB: Recover Data after an Unexpected Shutdown in Ubuntu
If you try to run mongod
but it fails to start and have this error in the log file (/var/log/mongodb/mongodb.log
) you’ll have to repair your db.
************** Unclean shutdown detected. Please visit http://dochub.mongodb.org/core/repair for recovery instructions. ************* Thu Dec 5 14:42:47.209 [initandlisten] exception in initAndListen: 12596 old lock file, terminating Thu Dec 5 14:42:47.209 dbexit: Thu Dec 5 14:42:47.209 [initandlisten] shutdown: going to close listening sockets... Thu Dec 5 14:42:47.209 [initandlisten] shutdown: going to flush diaglog... Thu Dec 5 14:42:47.209 [initandlisten] shutdown: going to close sockets... Thu Dec 5 14:42:47.209 [initandlisten] shutdown: waiting for fs preallocator... Thu Dec 5 14:42:47.209 [initandlisten] shutdown: closing all files... Thu Dec 5 14:42:47.209 [initandlisten] closeAllFiles() finished Thu Dec 5 14:42:47.209 dbexit: really exiting now
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/mods-available/mongo.ini
with this content:
extension=mongo.so
And create a symlink to it in /etc/php5/conf.d/
:
cd /etc/php5/conf.d sudo ln -s ../mods-available/mongo.ini 20-mongo.ini
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
- Page 1 of 5
- 1
- 2
- 3
- 4
- 5
- >