Saturday, 7 August 2010

Using 'checkinstall' tool with python source packages

Most python modules can be installed using a package management program. Important thing is, this modules can easily be uninstalled the same way. But if a module is only available as gzipped tar file (.tar.gz) source, installation is done using:

$ sudo python setup.py install


But there is no uninstall option and the manual removal of the files seems the only way.
Today I stumbled on the checkinstall tool. Here's what the manual say:

checkinstall is a program that monitors an installation procedure (such as make install, install.sh), and creates a standard package for your distribution (currently deb, rpm and tgz packages are supported) that you can install through your distribution's package management system (dpkg, rpm or installpkg).

Good thing it can also be used on python source packages, and it's really easy:

$ sudo checkinstall python setup.py install


This will prompt user for some answers and best thing is to use the default ones (in other words, just press enter). After this checkinstall will create a standard package file, and install it, in my case a .deb package. The module can now be uninstalled easily with a package management program.

Thursday, 5 August 2010

Debian: Setting Up JAVA - 'update-alternatives'

Got back to using Linux for a while now and I came up with some new stuff to put here. So this will be some kinda comeback to blogging since 2008.
This post will be adition to my last one about using update-alternatives command to setup which java VM your Debian system should use. Using this method is sometimes good enough, but for manual installation of java it won't work.
Let's say the java VM is unpacked as:

/opt/jdk1.5.0_09/


To succesfully use this version as default one the java command needs to be installed as a alternative first:

sudo update-alternatives --install /usr/bin/java java /opt/jdk1.5.0_09/bin/java 500


The last argument in the command is priority and it is mandatory. Priority is used when automatic mode for the link group is set. Any random number will do, for example '500'. Personally I don't know much about this so I won't go any further.

Last thing to do is executing one of this commands to use freshly installed java as default:

sudo update-alternatives --set java /opt/jdk1.5.0_09/bin/java
sudo update-alternatives --config java


That's all from me. Hope it helped someone.

Tuesday, 28 October 2008

Choosing which version of Java JRE system should use

Sometimes a number of various Java Runtime Environment versions is needed to be installed on a Linux system. To chose which one to use as a default use this command:

sudo update-alternatives --config java


An output like this will show up:

There are 6 alternatives which provide `java'.

Selection Alternative
-----------------------------------------------
1 /usr/bin/gij-4.3
2 /usr/lib/jvm/java-gcj/jre/bin/java
3 /usr/lib/jvm/java-6-sun/jre/bin/java
* 4 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
+ 5 /usr/lib/jvm/java-6-openjdk/jre/bin/java
6 /usr/bin/gij-4.2

Press enter to keep the default[*], or type selection number:


All to do here is enter the number of the selection next to the alternative JRE name and press enter.

Hope this was helpful. Enjoy.

Schedule fsck program to check disks on next reboot

It's not save to run fsck (file system check) while the disks are mounted. But it can be scheduled to run check on the next reboot simply by creating a file named 'forcefsck' on he root partition. Like this:

$ sudo touch /forcefsck

Friday, 19 September 2008

OpenSUSE: Install RPM packages with zypper CLI tool

Open Suse Linux uses RPM packages for software installation. Those files end in .rpm extension.
Most Suse users are familiar with the YaST graphic interface, but sometimes the quicker way to install a RPM package is from command line with the tool named zypper. This tool is similar to apt-get tool that Debian users use to install .deb packages and it uses already configured repositories to fetch packages. I'll explain its basic usage here.
All zypper commands have its longer and readable variant, and its shorter and less readable one. Commands for installing, removing and updating software needs root privileges.

Commands for software management:

Installing software

$ zypper install [package name]
$ zypper in [package name]


Removing software

$ zypper remove [package name]
$ zypper rm [package name]


Updating all installed software

$ zypper update
$ zypper up


Distribution upgrade

$ zypper dist-upgrade
$ zypper dup


Note: All of the above commands require root priviledeges.

Commands for software querying:

Search for packages matching a pattern

$ zypper search [pattern]
$ zypper se [pattern]


Show package information

$ zypper info [package]
$ zypper se [package]


Commands for repository management:

List all repositories

$ zypper repos
$ zypper lr


For all other commands and help type:

$ zypper --help

Wednesday, 17 September 2008

Vim feature that makes editing easier

Vim, along with the Emacs is the best free text editing choice in the Linux and OSS world. It has tons of features and improvements that can make text editing a lot easier and faster. I'll mention some of its features on the blog that I use the most.
This post is not a beginners tutorial or guide and I'm assuming that the reader has basic Vim knowledge such as entering/exiting insert mode, basic movement keys etc.
So let's get started.

One word replacement

Let's assume we have this line of text in our file:

Nikola Tesla was tha greatest engineer in tha world


Assume that the Vim is in the command mode and that the cursor is on the letter 'w' of the word 'world' also. This line has two typos in it an that is the 'tha' words. We need to substitute that typos with the right word 'the'. In the Vim editor that is done easily with the simple ex command:

:s/tha/the/g


First letter s of this command means substitute. Expression after the first slash presents the text we need to replace, and the second expression after the second slash presents the text to substitute with. Finally the letter 'g' in this command after the last slash says vim to replace every 'tha' occurrence in the line with the right word 'the'.
But what if we use the above command on this kinda sentence?

Nikola Tesla was tha greatest engineer in thailand


First three letters of the word 'thailand' will be substituted as well; the word 'thailand' is also a typo here cause it needs to start with the capital letter, but ignore that for now. The problem can be fixed with regular expressions that can be used in vim during a text search. Regular expressions are complex topic and I'm not gonna explain them here in depth. Let's just say that \< and \> can be used to mark start and end end of the word respectively, and our ex command would look like this:

:s/\<tha\>/the/g


This command works only on the line in witch cursor resides. To substitute each and every bad occurrence with new in the file this command is used:

:%s/bad/new/g


Read the '%' character as: do the commands on the whole file.
Substitutions that needs to be done from line 1 to 10 for example is used like this:

:1,10s/bad/new/g


Isn't Vim great?

Thursday, 11 September 2008

Find command: '-exec' action

There is a way to execute a command on each file using find and it is done with the -exec action argument.

For example, removing all backup files under the '/' directory and its subdirectories is done like this:

$ find / -name '*~' -exec rm '{}' \;


This means: execute rm command on each filename that ends with '~' on file system. The '{}' part of the command is replaced with the filenames that are found during execution, and escaped semicolon (\;) at the end represents the end of the -exec action argument.