Monday, December 21, 2015

Fix installation issues in Ubuntu

All of us have an ultimate responsibility to keep ourselves and our systems clean. Keeping ourselves clean is not what I am going to talk about here, noth anywhere else either. Keeping our systems clean, absolutely YES. Keep it clean, if you want to save both money and time.

Imagine those days on MS windows (even now, with a chuckle), some rogue application messed up few entries in registry. Result, hours of your time spent on reconstructing it, or you'd take it to the nearest shop, hope your machine can be revived. If you think such problems do not exist in LINUX, I can only pity your ignorance. However magnitude of issues are different. It's lot more easier to fix such issues in LINUX than on windows.

Wait, what am I talking about? Let's consider a mundane activity. As often is the case, you want to install some application that your fried raved about. You head to the application's download page, get source URL, add source to PPA list, to handle installation through package manager. If the source location is compatible with your OS version, you whistle your way to happiness. What if it is not?

If you happen to add a wrong source, every update command will start to complain. As a novice user you are lost on ideas. You are fret making changes to sources.list file. You spend hours togather reading documents for a clean way to get the hell out.

I even know a few who did not hesitate to reinstall OS. Yep, things can get that crazy. Luckily for me, it has never happened. Watch for my "past" tense. Yep, until today. It finally happened on me.

What was I doing?
I was installing MongoDB. Like any other curious developer, greedy to learn every new technology, I was eager to jump down the lane of MongoDB, try it out for my application. I mistakenly took wrong source from one of the BLOGS. Of course as always, mistake was mine. I should have read documentation, before I copied source. My excitement blinded me. Everything went well, until I did

 sudo apt-get update

There it showed up
Err vivid/mongodb-org/3.0/multiverse amd64 Packages 404  Not Found

This was followed by a few more obnoxious errors.

I have helped to fix similar issues half a dozen times for my dear ones. This time, I thought, why not fix & document it. BTW, this is not a problem that the worls is unaware of, but as the saying goes "More the MERRIER", I'll also join the fray.

As you can see, problem is because you added a wrong source.

Right way for you to clean up includes 6 steps
1. Stop running services, if any
2. Remove source from source.list file
3. Remove s/w from your computer
4. Cleanup your system
5. Re-install
6. Take a break

Step 6 is not optional :)

How do we go about

Step 1
Check to see if there are mongo services. If they are there, remove them
sudo rm /etc/init.d/mongod*

Step 2
Remove Mongo repository from your source.list
sudo rm /etc/apt/sources.list.d/mongo*

Step 3
Remove all mongo related s/w from your machine
sudo apt-get purge mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools syslog-ng-mod-mongodb

Step 4
clean up. Please do not ingnore this step. Somtimes you may be lucky, but not so lucky on your bad day. Remember, you are here because you had a bad day. Don't add to your problems.
sudo apt-get clean

Step 5
Add right repository, update and install
echo "deb wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install mongodb-org

Check if service is running
service mongod status

If it is not running, you can start the service by,
service mongod start

If you want to stop the service....
service mongod stop

Although I put an example of mongo, steps are similar for other applications too.

Next time you hit on a similar problem, don't fret, its easy clean up. Get back up like Cobra, after all life is not worth life without applies to LINUX more than anything. We learn the system better by mistakes, but make sure people don't notice it (If you are at fault).

Have a great day

Monday, December 14, 2015

HelloWorld in SWIFT

My first program in SWIFT

There's a lot to be excited about this open source project. For the moment this may look like more imbecile version. With time this may be a big player to develop first-class applications for LINUX and Mac alike. Perhaps, APPLE's way of informing developer community that it wants a piece in server side market.

What you'll see in this version of SWIFT?

Glad you asked. This is a minimal version of SWIFT for the moment. Not much to speculate, except for enjoying the beauty of this language. It does not have support for UIKit, nor or there any mention about IDE's. For the moment treat it like building a command line C application. I am sure APPLE will bring in some version of XCode for LINUX or have partnership with leading IDE's like Webstorm/Sublime/Atom for application development. All of which depends on APPLE's direction and thought process.

For this post, I used sublime text  (my choice of editor).

Head on to sublime text or any other editor of your choice. Put in the following code

print("Hello world!!!")

Save your file, name it helloworld.swift

Open terminal
browse to the location helloworld.swift
type in the following command

swift helloworld.swift

If you get any compilation errors, apart from code related issues, do the following

sudo apt-get install clang-3.6
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100

Re-compile your code
swift helloworld.swift

You should not see any errors.

Do ls -l
You'll see 2 files

One is the code you wrote and the other is compiled version of your code.

Execute helloworld

Hello world!!!

How to get started with SWIFT in Ubuntu

Here are some easy steps to get started with SWIFT in LINUX, particularly in Ubuntu. Steps are the same in other flavors too. `Although, you may want to watch for where you download source binaries from.

Head to for SWIFT libraries, download them
curl -O

Untar the file to local location
tar zxf swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04.tar.gz

I prefer to keep all my additional/specific installations in a single directory /opt. I am sure there are other players who have a directory of their choice. I know a few create a ~/lib directory, few add it to /var or even in /bin. What ever be your choice of directory, please move it into there 

sudo mv ./swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04 /opt

Open .bashrc file and add the following line of code. If you have moved to any other directory, make sure you make the right adjustments

vim .bashrc

Browse to the last line, add this one liner 

export PATH=$PATH:/op/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04

Run .bashrc to reflect your additions
. ./.bashrc

You are all set. Check if swift works by doing the following

swift --version