Monday, November 19, 2012

Uninstalling Ruby on Rails in Ubuntu Manually

Only do this if you installed RoR from Source.

It's playtime! Last week, I blogged how I was able to successfully install RoR from source despite several issues encountered. Now, I'm going to uninstall RoR manually. Most of you might think my previous adventure rendered some of my screws loose. Perhaps a little (hehe) but I assure you everything I type here is thoroughly tested so proceed at your own risk. ;)

I reason I have the guts to do crazy stuff is because I'm running Ubuntu in VM so I don't care much if I wreck numerous instances (which I did for the entire duration of my RoR installation journey) because I could easily reinstall Ubuntu. But this action has become tiring and very annoying. I admit I'm a newbie at both Ubuntu and Ruby and I'm doing this for educational purposes only. It's hitting two birds with one stone: I learn how to use Ubuntu (the terminal commands stuff) while experimenting on RoR installation.


According to Ruby homepage, there's three ways to install Ruby:

1) Compiling from Source 
    - We're done with this option.

2) Using third party tools (like rvm and rbenv)
    - I'm planning to use rvm for my next RoR installation attempt. If I'll have some spare time I might also use rbenv and maybe I'll do a post about which of the two is easier to use from a total beginner's perspective. Don't hold your breath though.

3) Using package management systems (like apt-get, aptitude and yum)
    - I'd read several articles/posts that warns against using this option (Ryan Bigg's guide comes to mind). I'm not going to push my luck and I'm going to follow their advice and be a good girl. After all they know what they're saying right?

This also translates that there are also three ways to uninstall Ruby: manually (refer to post below), using rvm (rvm uninstall version_number) and using apt-get (sudo apt-get purge ruby).



Without further ado, let's start.

The sequence we installed RoR last time was Ruby + RubyGems + Rails. We're going the opposite way in uninstalling: Rails (with dependencies) first, then RubyGems and Ruby.


To uninstall Rails + all dependencies:

gem list --no-version | xargs sudo gem uninstall -ax

I got this one-liner from James McGrath's post. If you want to know the meaning for each switch used, he explained it very well in his post.


To uninstall all gems except for one:

gem list --no-version | grep -v rails | xargs sudo gem uninstall -ax

This will uninstall all gems (Rails dependencies and other gems installed) except for Rails (remember Rails is also a gem).


To delete only the old versions:

gem clean


To uninstall specific gem:

sudo gem uninstall rails

This will uninstall Rails gem only.


To uninstall RubyGems and Ruby (in one sweep):

sudo rm /usr/local/bin/{ruby,irb,gem,testrb,erb}
sudo rm /usr/local/lib/libruby-static.a
sudo rm -r /usr/local/lib/ruby/


To check:

whereis ruby
whereis gem


Wednesday, November 14, 2012

VirtualBox: Enable Shared Clipboard (Copy - Paste) From Host (Win 7) to Guest (Ubuntu 12.04) and Vice versa

1. Check if you have VirtualBox Guest Additions installed.

Open Terminal (Ctrl  + Alt  + T)
Type modinfo vboxguest



If VirtualBox Guest Additions is already installed, proceed to step 3.

2. Install VirtualBox Guest Additions



3. Enable Shared Clipboard.

Machine > Settings > General > Advanced

In Shared Clipboard, choose whichever option you need. I chose Bidirectional for seamless copy - pasting. You can also enable Drag 'n Drop if desired.

image-705623.png (320×240)

Then reboot. Type sudo reboot

Tuesday, November 13, 2012

Solution to “ruby installation is missing psych” Error

To save yourself from this headache, install yaml first before installing Ruby. 


I'm still trying to install Ruby on Rails on Ubuntu 12.04 and I got this warning after I installed RubyGems:

It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby.

I googled this error and it seems several people had this problem too. A bug??? Yep. (If you're installing Ruby from rvm, refer to thisthis and/or this) Unfortunately, their solutions won't work for me because I'm installing Ruby from source not from rvm. So I decided to follow the instruction please install libyaml and reinstall your ruby and prayed it'd work.

I installed libyaml:

tar -xvzf yaml-0.1.4.tar.gz
cd yaml-0.1.4/
sudo ./configure && sudo make && sudo make install

Then "reinstalled" Ruby from Source:


wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz
tar -xvzf ruby-1.9.3-p327.tar.gz
cd ruby-1.9.3-p327/
sudo ./configure && sudo make && sudo make install

When I typed gem -v, I still got the same error. :( I googled for the error and found this SO answer as my saving grace.

I recompiled yaml module:

cd ruby-1.9.3-p327/ext/psych
sudo ruby extconf.rb
sudo make && sudo make install

Judgement time. *drum roll*  To test, I typed gem -v

Aaaaaaaaaannnnnndddddd no error. I got my gem version: 1.8.24. Yipee. :)

Sweetness... 


A little explanation for myself (and to others who are curious):
## recompiles yaml or any other module
cd ruby-1.9.3-p327/ext/<module folder>
sudo ruby extconf.rb

## reinstall Ruby
sudo make && sudo make install

Monday, November 12, 2012

Converting BeautifulSoup 4 for Python 3


According to BeautifulSoup homepage, the latest release (Beautiful Soup 4.1.3) is compatible for both Python 2.x and Python 3.x. However, to use BS 4 in Python 3.x, you will need to manually convert the code using 2to3.

Windows 7:


Download BS 4.


cd C:\beautifulsoup4-4.1.3
python C:\Python33\Tools\Scripts\2to3.py -w bs4
python setup.py install

**-w option means overwriting the original file



Ubuntu 12.04:


** Setup proxy if you need to.


wget http://www.crummy.com/software/BeautifulSoup/bs4/download/beautifulsoup4-4.1.3.tar.gz
tar -xvzf beautifulsoup4-4.1.3.tar.gz
2to3 -w beautifulsoup4-4.1.3/bs4
cd beautifulsoup4-4.1.3/
sudo python3 setup.py install


To check if BS4 was properly installed, type in your Python 3 interpreter: 

>>> from bs4 import BeautifulSoup

Sunday, November 11, 2012

Setting up Proxy Settings for apt-get and wget in Ubuntu

To check if you have proxy configured in your system:
env | grep proxy

To setup proxy, add the following lines to these environment settings:

1) apt.conf (for apt-get)

sudo gedit /etc/apt/apt.conf

Acquire::http::Proxy "http://username:password@proxy:port";
Acquire::https::Proxy "http://username:password@proxy:port";
Acquire::ftp::Proxy "http://username:password@proxy:port";

2) wgetrc (for wget)

sudo gedit /etc/wgetrc

https_proxy  = http://username:password@proxy:port
http_proxy = http://username:password@proxy:port
ftp_proxy = http://username:password@proxy:port

Uncomment 'use_proxy = on'

Then reboot. sudo reboot


After rebooting your machine, you can now use apt-get and wget normally like sudo apt-get install package-name and wget url

If you don't want to change any configurations and just wanted to use proxy for the entire duration of your session:

For apt-get:
sudo http_proxy='http://username:password@proxy:port' apt-get install package-name

For wget:
export http_proxy='http://username:password@proxy:port' && wget url

OR

export http_proxy=http://proxy:port && wget --proxy-user=user --proxy-password=password url

Things to remember: 
1) Use this format if your proxy doesn't require login credentials: http://proxy:port
2) If your proxy server is Windows-based just like ours, don't forget to add your domain in your login.
ex. http://domain\username:password@proxy:port
3) Character escape your password if it has special characters.
ex. proxy-password=me\@123
4) If after setting up the http_proxy environment variable for wget and the connection still fails, also set up the https_proxy and ftp_proxy variables.

Sharing Files from Windows 7 to Ubuntu 12.04 Via VirtualBox

A coworker inspired me to learn a new OS. Since I'll be using my work machine, I opted to use VM and installed Ubuntu 12.04. Ubuntu 12.04 has Python 2.7 pre-installed. I also installed Ruby 1.9 and Rails 3. I found several posts on how to setup Ruby on Rails (RoR), however, I encountered problems because I'm stuck behind the friggin' corporate proxy. Read my RoR installation misadventure here.

The first thing I did aside from learning some basic commands like shutting down the VM, editing some files, etc via terminal was to research how to share files from Win 7 to Ubuntu. Here's how:

1. Check if you have VirtualBox Guest Additions installed.

Open Terminal (Ctrl + Alt + T)
Type modinfo vboxguest


If VirtualBox Guest Additions is already installed, proceed to step 3.

2. Install VirtualBox Guest Additions. 


3. Go to VM VirtualBox Manger Settings.



Add folder you wanted to share.



From the Visual Box User Manual:

Access to auto-mounted shared folders is only granted to the user group vboxsf, which is created by the VirtualBox Guest Additions installer. Hence guest users have to be member of that group to have read/write access or to have read-only access in case the folder is not mapped writable.



Add user that wants to access shared folder:

Type sudo adduser <username> vboxsf







To remove a user from vboxsf group:

Type sudo deluser  <username> vboxsf




Then reboot for your changes to take effect. Type sudo reboot.


To view your shared folder, go to File System > media.




Check out Liberian Geek and SysProbs for more Windows-Linux tutorials.

Friday, November 9, 2012

A Reason for An Introduction to Cyberspace

Finally, a reason (an excuse really) to blog! I wanted to create a blog for the longest time now, however I don't have much stuff to write about (now I do) and I don't want to be another clutter in the cyberspace. Anyways, I made this blog for the sole purpose of tracking my solutions for problems/errors/technical issues I've encountered at work. If my ramblings can also help others, that will be great! :)

My machine specs written below for future reference:

Work:
- Windows 7, 64-bit
- .Net 3.5 and 4
- VS 2008 and 2010 Ultimate
- LinqPad
- Notepad++
- SQL Server 2008
- has Virtual Box installed and runs Ubuntu 12.04
- both OS have Python (2.7 and 3.3) and Ruby (1.9) installed
- Rails 3 installed in Ubuntu
- corporate proxy (super PITA!)

Home:
- Windows 7, 32-bit
- .Net 3.5 and 4
- VS 2008 and 2010 Ultimate
- LinqPad
- SQL Server 2008
- Notepad++
- Python 2.7 

Other specs like RAM, processor etc will be mentioned if ever the need arises.

So much for an introduction. That's all for now. Enjoy the roller coaster ride ahead!