Private

Hi all,

Just a quick post to announce the availability of a nodeJS PPA repository for Ubuntu 12.04. This PPA currently supports nodeJS 0.6.11 and npm 1.1.1-7 but I’ll be aiming to update as the new stable releases come out. Hopefully this will enable more of you to work with the current stable release of nodeJS instead of the ubuntu/debian default which at the time of writing is on the 0.4.x branch.

You can read more about the repository here:

https://launchpad.net/~richarvey/+archive/nodejs

or easily add the repo by running this from the command prompt:

sudo add-apt-repository ppa:richarvey/nodejs

For those of you wishing to know more about nodejs hop on over to http://nodejs.org

by-nc
, , ,

A Quick VIM Primer

When you read a lot of HOWTO’s and guides for Linux you’ll often find commands that say edit a file in vi or vim. However we (old skool admins) tend to forget how infuriating these editors can be for new users, so here a little primer that will hopefully get you going. Vim is extremely powerful and is normally installed either as vi or vim on most systems, its lightweight and quick to edit a file remotely on your server for example.

Getting Ready.

First of all lets get you using vim (Vi improved) rather than vi. from a terminal run:

sudo apt-get install vim vim-scripts

vim-scripts isn’t needed but I’ll touch on some articles about using them at a later date.

Now lets make vim your default terminal editor.

update-alternatives –config editor

Select the option /usr/bin/vim.basic

Basics.

Ok now lets create and work on a file. Run:

vi testfile.txt

You’re now faced with a blank screen, and at present no way of entering text. BEFORE pressing anything else press insert, you’ll notice “testfile.txt” [New File] changes to — Insert –. If you press insert again it will say — Replace –. These are the main edit modes we’ll cover in this primer, I’m sure you can work out the difference between insert and replace.

So now you can start typing. As you can see its very basic, but that’s all yo need to edit most files.

Now lets say you want to save your work. Firstly we must exit insert mode. To do this press Esc. The line which once said — Insert — is now blank. To enter any command in order to make vim do things like save and exit you need to use the colons : As you press this you’ll see it appear in the bottom left hand corner. To save your work type w (short for write) followed by enter. The status bar at the updates to tell you the file is written. Now if you want to edit the file simply press insert again!

To exit vim completely press Esc to get out of editor mode followed by : then q (short for quit) followed by enter. NOTE: this will not save changes you make to the file. To save and quit use Esc :wq followed by enter.

If you’ve opened a file edited it then decided its now not what you want to do, vim wont let you exit the file before saving. To over come this use ! to force a command. Esc :q! then enter means quit and don’t worry about prompting me to save.

Quick deleting.

Now lets do some more advanced stuff. Image you just need to open a file and delete a section. For this you don’t even need to go into editor mode (– Insert –). Lets try this by working on your file. Make sure you have a couple of lines of text, separate lines would be even better. Now exit edit mode by pressing Esc. You notice you can still move the cursor around on the text but you can’t actually go right to the end of a line and start typing new text. Move your cursor to the beginning of some text you want to delete and press x. Yes you can see it deleted the letters from in front (to the right) of the cursor. Now that’s great for quickly deleting a few bits then saving the file and exiting. But what if you want to delete a complete line? Simple move your cursor to that line and press d twice. Bang its gone!

Copy/Paste.

You can always highlight text from anywhere by just left click on the mouse and dragging as per normal, but if you’re new to Linux, you may not know that you can then just simply paste by middle clicking in the new document. You can use these features in the terminal also. However vim offers a few tricks of its own. For example lets say you want to duplicate a line of text already in your document and move it else where. Make sure you are NOT in editor mode, move the cursor to the line you want to copy and press Y (short for yank also note its a capital). Now move the cursor to somewhere else in the document and press p. Your line gets pasted. Now use this with the delete command and you can move text round your document easily. Also you’ll find if you delete a line using dd you can then paste it somewhere else using p.

Stacking up commands.

Now you know how to Yank and Delete lines, what if you want to do more than one line? Simple before your command type a number. For example 2dd will delete two lines. 5Y will copy five lines. Give this a go as it will get you used to the concept that vim is very flexible with its commands.

Syntax and line numbers and strange pasting.

Lets say you’re editing a .php file. Vim can highlight the code and show you incorrect syntax or even make it easier to see the start and end of {} or <>. To turn this feature on type Esc :syntax on then press enter and the magic will happen. You may also want line numbers just type Esc :set number on. You can of course turn these off by swaping on for off in the previous commands. If you find when you paste some text from a website it goes haywire when inserted into vim turn off AI which tries to work out what the indentation should be Esc :set noai

A good trick is to switch these features to be always on, to do this create a file in your home directory called .vimrc

vi .vimrc

add these lines

syntax on

set number on

set noai

Now exit vim and open a .php file. You’ll see the features are automatically turned on.

Search and Replace.

I use this command a lot! Its incredibly handy for editing config files. This is fairly advanced for this primer but as I use it so much I though you’d find it useful also. I’ll start by just showing you the command and then breaking it down. Yet again start by leaving insert mode, by pressing Esc.

:1,$ s/foobar/moo/g

Lets break this down so it doesn’t look so confusing.

: – Colons as mentioned before precede any command.

1,$1 tells the command to start on the first line of the text (you could start on line 20 by just swapping this) you then need to follow that with a , and then you use the line where you want to stop this command running, so if you want to go to the end of the file use $ and vim works out this number automatically. However if you want to stop on line 30 and start on line 20 do something like this :20,30

s/ – is used to say swap anything matching the text after this line /

foobar – this is your first string so this should match the word you’re looking to replace.

/ – Separate the word you’re searching for with the new word.

moo – This is your new word.

/ – Tell the command that’s the end of the new word

optional g or ig means global this means every occurrence of the work in you file will be replaced (within your start and end line numbers) If you don’t use g you may find it only updates the first occurrence in each line. i will make the search case insensitive which can be useful. You can use both g and i together as so /gi

Hopefully this will help you start using vim and get confident with day to day tasks. There is MUCH more this editor can do, I recommend looking at The vim Cheat Sheet.

by-nc
, , , , ,

There are a handful of desktop virtualization products which work on Linux such as VMware, Virtual Box UML and so on. However KVM is a upcoming star in this busy market place. KVM (kernel virtual machine) is a upstream supported virtualization product. Redhat and Canonical are both betting hard on this technology with it becoming standard in RHEL6 and its already the power house behind Ubuntu Enterprise Cloud. If your looking to use desktop virtualization rather than server virtualization its very easy. In this simple tutorial I’ll show you how to get up and running with a NAT’d connection that will provide your guest access to the internet via the use of a local (on your PC) network. Later on this blog I’ll cover more advanced topics such as a bridged networks, which will allow the virtual machine to appear as if its a real machine on the network.

Prerequisite’s:

First lets see if your machine can use KVM technology by checking if your processor supports the hardware acceleration required, from a terminal run these commands:

egrep -c ‘(vmx|svm)’ /proc/cpuinfo

This will return a numeric value. Anything above 0 is good. If you see a zero then I’d recommend using something like Virtualbox which will run a little slower as your processor doesn’t support virtualization. Newer processors should be fine and they provide an abstraction layer that allows the guest virtual machine to interact directly with the hardware, thus you get a speed boost!

NOTE: You may need to go into BIOS and enable virtualization (This is vendor specific and will boost the speed of all the virtualization on your machine).

If you want to give more than 2GB of RAM to your VM’s you need to be on a 64bit computer. You can check this from the terminal by running:

egrep -c ‘lm’ /proc/cpuinfo

0 means your on a 32bit machine 1 means 64bit and your good to go.

Installation:

Now you’re ready to install. From the terminal run:

sudo apt-get install qemu-kvm libvirtd-bin virt-viewer

Thats It you should be done. If you want to check that the KVM module is loaded from the terminal run:

lsmod | grep kvm

If you don’t get any output simply run:

sudo modprobe kvm

You also need to to make sure libvirtd is enabled and running.

sudo gedeit /etc/default/libvirt-bin

Make sure you have this line (you may have to edit it) start_libvirtd=”yes”

Now start libvirtd

sudo service libvirt-bin start

Now back to the gui go to Applications -> System Tools and click Virtual Machine Manager, your almost ready to create your first machine. Now just click File -> Add Connection and accept the defaults from the pop up window like the image below:

Now if you click the icon in the top left hand corner of virt-viewer you will be greeted with a wizard to build your first virtual machine. I selected install from ISO for this but you could equally use any of the other options, if you have the correct things in place to do so.

Now point the Use ISO image box to the location of the ISO you wish to use. I also set the OS type and Version although this isn’t necessary.

Now you have the option to set the RAM you wish to dedicate to the machine and number of virtual CPU’s. The max number of VCPU’s is dictated by the output from the egrep -c ‘(vmx|svm)’ /proc/cpuinfo command you ran before, which shows you how many of your core’s support the virtualization extensions.

The next stage asks you to set the size of the virtual hard disk for your new machine, I went for the standard 8GB as this is just a test server instance.

The next screen provides a summery of your options and allows you to pick virtual networking adaptor. As we haven’t set up any bridging yet leave this as the default.

Once you click finish your machine should start running. If you click on the VNC window that’s now popped up and your Keyboard and Mouse become locked to that screen press CTRL+ALT and you’ll return to your desktop.

by-nc
, ,
Private
You are protected by wp-dephorm: