Install Python 3 locally under /home directory in CentOS 6.4

First off, why would you want to install local Python 3? There could be many reasons, some of which may be:

  • You don’t want to touch the system-installed Python
  • You don’t have root privileges
  • You want to run your private/personal scripts without affecting other users on the system
  • You want to run multiple versions of Python not available on your system

For whatever the reasons you want to install Python locally in your home directory, it’s not as difficult as I had first thought it to be. This is a good alternative especially since Python3 is not officially available in CentOS 6.4.

There are four major steps:

  1. Install Development Tools
  2. Download Python Source Code
  3. Compile and Install Python
  4. Modify your $PATH

Install Development Tools

You will need some tools to compile Python. The easiest way to obtain them in CentOS is to install the ‘Development Tools’ group.

cg@codeghar [~] $ su -c 'yum groupinstall "Development Tools"'

You also need some libraries that Python uses to provide “batteries included” support.

cg@codeghar [~] $ su -c 'yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel'

Download Python Source Code

Head over to and download the version you want to install. For this post I used Python 3.3.2.

cg@codeghar [~] $ curl -O

Now just un-tar the file so you can use its contents.

cg@codeghar [~] $ tar xvf Python-3.3.2.tar.bz2

You should see these two items in your home directory:

cg@codeghar [~] $ ls

Python-3.3.2  Python-3.3.2.tar.bz2

Compile and Install Python

You now have Python source and tools to compile it. Change directory to the un-tar’ed source code.

cg@codeghar [~] $ cd Python-3.3.2

Run configure.

cg@codeghar [~/Python-3.3.2] $ ./configure

Create a directory where you will install your local Python.

cg@codeghar [~/Python-3.3.2] $ mkdir -p ~/usr/local

Compile and install Python to the directory you just created.

cg@codeghar [~/Python-3.3.2] $ make altinstall prefix=$HOME/usr/local exec-prefix=$HOME/usr/local

Modify your $PATH

You now want to add ~/usr/local/bin to your $PATH so you don’t have to enter the full path to the Python binary every time you want to use it. Change directory to where local Python binary is located.

cg@codeghar [~/Python-3.3.2] $ cd ~/usr/local/bin

Create an alias so you can refer to it as python3. This is optional but I like to do it because I can then use python to refer to the Python that came with CentOS and python3 to refer to my locally installed Python3.

cg@codeghar [~/usr/local/bin] $ ln -s python3.3 python3

Now add this path to your $PATH environment variable. Notice that we add the new path before existing $PATH. This is so that our local Python is always used before any other.

cg@codeghar [~/usr/local/bin] $ echo "export PATH=\$HOME/usr/local/bin:\$PATH" >> ~/.bashrc

When you open a new terminal window, or log off and then log on, or (even better) run source ~/.bashrc, you can run the following commands to see that your local Python is now on your path.

cg@codeghar [~] $ which python3.3


cg@codeghar [~] $ which python3


cg@codeghar [~] $ which python


You can even run your local Python.

cg@codeghar [~] $ python3

Python 3.3.2 (default, Sep 26 2013, 15:30:36) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("Hello World!")
Hello World!


You can now run your local Python. There’s no need to keep the tar file and the source code around. You may want to delete them.

cg@codeghar [~] $ rm -rf ~/Python-3.3.2

cg@codeghar [~] $ rm ~/Python-3.3.2.tar.bz2

Another thing to consider is virtual environments, virtualenv or venv (in Python 3). Since Python3 comes with its built-in venv, just create an alias for its binary as well.

cg@codeghar [~] $ cd ~/usr/local/bin

cg@codeghar [~/usr/local/bin] $ ln -s pyvenv-3.3 pyvenv

There’s one more modification you need to make to get pyvenv to work. Open the file and change the path to your locally installed Python.

cg@codeghar [~/usr/local/bin] $ vim pyvenv-3.3

Original line is:


After changing it should look something like:


You can now use this local pyvenv to create your virtualenvs.

Hat Tips

How to install locally python on linux home directory?; Installing Python 3 on CentOS/Redhat 5.x From Source; UNIX / Linux: Set your PATH Variable using set or export command; .bash_profile vs .bashrc; RHEL / CentOS Linux Install Core Development Tools Automake, Gcc (C/C++), Perl, Python & Debuggers

Working with Third Party Repositories on CentOS 6.4

I have been playing around with CentOS a bit. It has older versions of all software I use or is missing some other software I need. The first problem (older version of software) is remedied by using additional repositories: Software Collections, IUS. The second problem, missing software, is also remedied by additional repositories: EPEL, RepoForge (formerly RPMForge).

You may want to list your current repositories:

yum repolist

When adding a repository, find the rpm that’ll add/enable the repository. You’ll usually find these on the project’s website. For example, RepoForge, IUS, EPEL have instructions and links on where to find the rpm.

As an example, we’ll add the RepoForge repository.

rpm -ivh ''

You could also use yum to install the rpm:

yum localinstall

Now when you list the repos on your machine, you’ll see something like:

yum repolist

Loaded plugins: fastestmirror, presto, ps
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * extras:
 * rpmforge:
 * updates:
repo id        repo name                                            status
base           CentOS-6 - Base                                      6,381
extras         CentOS-6 - Extras                                       13
rpmforge       RHEL 6 - - dag                          4,597
updates        CentOS-6 - Updates                                   1,123
repolist: 21,606

To view the packages available from a repository, disable (temporarily) all repos except the one you’re interested in.

yum --disablerepo='*' --enablerepo='rpmforge' list available

To remove a third party repository, first find the rpm and then remove it.

rpm -qa rpmforge*


Or you can use yum:

yum list rpmforge*

If you’re curious to know what the removal will look like, you can test it first.

rpm -e --test -vv rpmforge-release-0.5.3-1.el6.rf.x86_64

D: loading keyring from pubkeys in /var/lib/rpm/pubkeys/*.key
D: couldn't find any keys in /var/lib/rpm/pubkeys/*.key
D: loading keyring from rpmdb
D: opening  db environment /var/lib/rpm cdb:mpool:joinenv
D: opening  db index       /var/lib/rpm/Packages rdonly mode=0x0
D: locked   db index       /var/lib/rpm/Packages
D: opening  db index       /var/lib/rpm/Name rdonly mode=0x0
D:  read h#     200 Header sanity check: OK
D: added key gpg-pubkey-c105b9de-4e0fd3a3 to keyring
D:  read h#     261 Header sanity check: OK
D: added key gpg-pubkey-6b8d79e6-3f49313d to keyring
D: Using legacy gpg-pubkey(s) from rpmdb
D:  read h#     265 Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: OK
D: ========== --- rpmforge-release-0.5.3-1.el6.rf x86_64/linux 0x0
D: opening  db index       /var/lib/rpm/Requirename rdonly mode=0x0
D: ========== recording tsort relations
D: ========== tsorting packages (order, #predecessors, #succesors, tree, depth)
D:     0    0    0    0    1   -rpmforge-release-0.5.3-1.el6.rf.x86_64
D: erasing packages
D: sanity checking 1 elements
D: computing 26 file fingerprints
D: computing file dispositions
D: opening  db index       /var/lib/rpm/Basenames rdonly mode=0x0
D: 0x0000fd00     4096    121121780     32464498 /
D: ========== +++ rpmforge-release-0.5.3-1.el6.rf x86_64-linux 0x0
D:     erase: rpmforge-release-0.5.3-1.el6.rf has 26 files, test = 1
D: closed   db index       /var/lib/rpm/Requirename
D: closed   db index       /var/lib/rpm/Basenames
D: closed   db index       /var/lib/rpm/Name
D: closed   db index       /var/lib/rpm/Packages
D: closed   db environment /var/lib/rpm

Now you can remove the repo:

rpm -e rpmforge-release-0.5.3-1.el6.rf.x86_64

Or you can use yum:

yum erase rpmforge-release

Additional Resources:
RedHat software collections and CentOS

Appreciate CentOS Day

I’d like to take an opportunity to declare today the Celebrate CentOS Day. This project provides not only a free-of-cost RHEL alternative but makes it very easy to get up and running. I am specifically thankful for the minimal installer, taking out the guesswork involved in building a minimal server. To provide support for the lifetime of the upstream project is a major task and is appreciated as well. Keep up the good work, CentOS team!

My yum Got Stuck

I was upgrading using yum in a newly installed Scientific Linux 6 and during the last clean up yum just got stuck. I did a ctrl+c and stopped the process. A reboot worked fine as well. However, suddenly a message popped up saying there was an error in yum and told me to run a command as root: yum-complete-transaction. This ought to have solved any problems created when I forcefully quit a running yum transaction.

Install Virtualbox on Centos

I finally found good working guide of package installation of virtualbox 3.1.x on Centos 5.4 . I would like to share this thing with one who is looking for it. Hope will help.

Step 1:
First we have to get Sun’s public rpm key:

[root@~]# wget -q
[root@~]# rpm --import sun_vbox.asc
[root@~]# rm -f sun_vbox.asc

Step 2:
Now we have to enable the VirtualBox OpenSUSE repository on our system:

[root@~]# cd /etc/yum.repos.d/
[root@~]# wget

Step 3:
Install VirtualBox 3.1.x

[root@~]# yum install VirtualBox-3.1

Step 4:
Now you must add the user that will run VirtualBox (admin in this example) to the vboxusers group:

[root@~]# /usr/sbin/usermod -G vboxusers admin

VirtualBox is now installed and ready to be used.

To access virtualbox goto Applications->System Tools->Sun VirtualBox



USB devices greyed out in Virtualbox [Solved] – Centos

On my Centos 5.4 I installed Virtualbox and run Windows XP guest OS on it. After installation it showed available USB devices but all were greyout or disabled. After searching for the solution on net for 2 days i finally get it working by  following the steps below.


Findout gid number by typing

# grep vboxusers /etc/group

you will get output like this


Note down the number between :XXX: in this case it is 501

Step 2:

Now make sure none of the usb devices attached to the PC.

goto root level and run the follwoing commands

[root@~]# umount /proc/bus/usb
[root@~]# mount -n -t usbfs /proc/bus/usb /proc/bus/usb -o devgid=501,devmode=664

put devgid value  which you get above.

Step 3:

Now open your virtubalbox and run the OS, you will see all your USB devices enabled.



Hat Tips: Virtualbox Forum