Install latest (or specific) version of Node.js on Ubuntu Linux

The typical way to install Node.js in Ubuntu Linux is to use the apt-get package manager (i.e., sudo apt-get install nodejs). However, the Ubuntu repositories tend to lag a good bit behind the latest version of the platform. In this tutorial, we’ll install Node.js by downloading the source and compiling it ourselves. We will install it our local $HOME directory to avoid any conflicts with the standard package. This tutorial should work fine on your local Ubuntu machine, as well as a Ubuntu Vagrant box virtual machine (VM).

First, we need to update our system and install a few packages, if they aren’t already installed. Specifically, we need to install build-essential, which contains the GCC C++ compiler, and curl for downloading files from the Internet via the command line. At the command prompt, run these commands:

sudo apt-get -y update
sudo apt-get -y install build-essential curl

To install Node.js to our $HOME directory, we need to add $HOME/local/bin to the PATH environment variable and then export it to our environment by running:

echo 'export PATH=$HOME/local/bin:$PATH' >> $HOME/.bashrc
. $HOME/.bashrc

Now, create two new directories, local and node-latest-install, in the $HOME directory. These directories will hold the installed version of Node.js and the Node.js source code, used to compile the new version, respectively.

mkdir $HOME/{local,node-latest-install}

Next, we change to the node-latest-install directory, download the Node.js source code and extract the source code into that directory.

cd $HOME/node-latest-install
curl -LOk
tar xz node-latest-tar.gz --strip-components=1

This will get the very latest released version of Node.js. If you prefer a specific version, navigate to in your web browser and find the appropriate directory and file name ending with tar.gz. For example, to download the “latest” version from the 4.x branch (which at the time of writing is 4.2.2), we would download

Finally, we compile the Node.js application. Notice specifically that we specify to install to the $HOME/local directory.

./configure --prefix=$HOME/local
make install

Depending on the speed/power of your machine, compiling may take several minutes. The main thing to look for is whether or not any errors are returned. If you get errors while compiling, ensure that you have build-essential package installed.

To verify that Node.js installed successfully, run node -v and the command prompt. It should return something like v4.2.2. To confirm that you are running Node.js from the local installation, you can run which node at the command prompt, which should return something like /home/username/local/bin/node where username is your username (or vagrant, if you are installing on a Vagrant box).

The Node.js installation also includes the Node Package Manager (NPM). This is the official package manager for Node.js and allows you to install almost any package for Node.js that you could need. In particular, NPM is required to use Laravel Elixir, Laravel’s development task running, which acts as a wrapper for Gulp.


Fix ‘403 Forbidden’ error on Apache 2.4 HTTP server in Ubuntu

In the latest versions (specifically version 2.4.3 and above) of the Apache 2.4 HTTP server, on a new installation, you may receive the ‘403 Forbidden’ HTTP error when attempting display your site.  To increase security, the Apache developers changed the default configuration to block all requests.  To fix this, you must explicitly grant permissions via your site configuration file.

In Ubuntu Linux, you will need to edit the appropriate site configuration file.  Typically, the name of this file is 000-default.conf and it is located in /etc/apache2/sites-available directory. Open this file in a text editor (remember to open it using sudo, since it is a system file) and add the following line in the <Directory> section:

Require all granted

For example, the updated <Directory> section may now look like:

        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
                Require all granted

To make this change take effect, you must restart the Apache web server using this command:

sudo service apache2 restart


Stack Overflow – Apache VirtualHost 403 Forbidden

Increase session time-out in phpMyAdmin

If you do any development with PHP and MySQL, undoubtedly, you are familiar with phpMyAdmin, which is a web-based tool for managing and editing MySQL databases. While phpMyAdmin is an excellent tool, one of it’s annoying aspects is the default session time-out of 30 minutes. However, you can make a quick configuration change to extend the time-out to most any value that you like.

To do this, just open the file for phpMyAdmin (which is in the /etc/phpmyadmin directory on Ubuntu Linux) in an editor as the administrative user (i.e., use sudo in Linux). Then, add these lines within the 'Servers' configuration section:

/* Set session time out to 8 hours (28800 seconds) */
$cfg['Servers'][$i]['LoginCookieValidity'] = 28800;

Save the changes and restart the Apache web server:

sudo service apache2 restart

The next time that you log into phpMyAdmin, you will stay logged in for 8 hours (or whatever duration you specified). For more information, see phpMyAdmin documentation for LoginCookieValidatity.

Install latest version of Adminer MySQL administration tool on Ubuntu Linux

Adminer is a lightweight, PHP-based MySQL administration tool that is a great alternative to PHPMyAdmin. It comes as a single file and can easily be installed globally on your Ubuntu Linux box, including a Vagrant box.

The prerequisites for installing and using Adminer are PHP, MySQL, and Apache, the so-called LAMP stack. To install them on Ubuntu, in the terminal, run:

sudo apt-get install php5 php5-cli php 5-mysql mysql-server apache2

You’ll be prompted for configuration information during the installation.

Once the LAMP stack is installed, install Adminer by running these commands in the terminal:

sudo mkdir /usr/share/adminer
sudo wget -O /usr/share/adminer/latest.php ""
sudo ln -s /usr/share/adminer/latest.php /usr/share/adminer/adminer.php
echo "Alias /adminer.php /usr/share/adminer/adminer.php" | sudo tee /etc/apache2/conf.d/adminer.conf
sudo service apache2 restart

After installing Adminer, open a web browser and navigate to http://localhost/adminer.php. The Adminer login screen should be displayed. You can now log in to any of the MySQL databases configured.

If you want to upgrade to a new version of Adminer later, since you created a symlink to the latest.php, you can simply run this command in the terminal:

sudo wget -O /usr/share/adminer/latest.php ""

Prevent upgrade of (“lock” version) specific packages in Debian/Ubuntu Linux

In many cases, you may need to preserve the current version of a package in Debian or Ubuntu Linux. For example, your production environment may use an older version of a package and, in your development environment (perhaps on a Vagrant virtual machine), you want to make sure you use the same version. The apt package manager provides functionality to “lock” (or, as it’s called in Debian/Ubuntu, to “hold”) the version of a package. The command is simple:

sudo apt-mark hold package_name

where package_name is the name of the package, such as grub-pc. You can include multiple package names on the command line by separating each with a space.

For more information, see the Ubuntu help topic on apt “pinning”.

Use PHP array_map() function to remove white space from array elements

One common scenario in PHP is take an input list, such as some search criteria entered by a user, and tokenize the input into individual items using a separator, such as comma. The PHP explode() function works great for splitting up the individual values into an array(). However, if have white space before or after the separator, each of the elements of the new array will contain that white space. You could use a foreach loop, with the $key => $value syntax to apply the trim() function to each item. But PHP has the perfect function already built in: array_map().

array_map() takes a callback function as its first argument and an array as the second argument. It applies the specified callback function to each element of the array that is passed in. You simply provide the name of the callback function as a string (either in single or double quotes) and the function can be a function within your code or any of the built-in PHP functions. For example, to put all of the pieces together, you could do something like this:

$input = "apricot, banana, cherry, dewberry, eggplant, fig";
$output_trimmed = array_map("trim", explode(',', $input));

Make your .bash_profile aliases available anywhere

Bash aliases are one of the truly great timesavers when working in Unix/Linux. I’ve picked up quite a few aliases from others on my travels around the Internet and many have become second nature. Moreover, in quite a few cases, I’ve (almost) forgotten the original command!

Lately, I’ve done a lot of development work using Vagrant and, honestly, I’d never want to go back to trying to set up development environments on individual machines, since Vagrant makes standardization so simple. At the same time, even though my Vagrant box is pretty well standardized, everyone probably has their on bash aliases that they like to use. So, here’s how to have the best of both worlds!

What we want to do is provide a simple way to grab our bash aliases from Github and apply them from most any machine.

  1. Put your bash aliases (or any other bash settings!) into a file a file named .bash_alias and add this file to your Github account. The conventional practice is to put these in a repository named dotfiles.
  2. Determine the “raw git” URL to your new .bash_alias on Github. Essentially, this URL starts with and then follows the standard pattern for Github URLs of your username, repository name, branch, and file name. For example, my .bash_aliases “raw” URL is
  3. Now, here’s where all of the magic happens! When you want to apply your aliases on a machine that you are logged into, such as a Vagrant box, just run this command at the shell:
    curl -o /tmp/.bash_aliases; source /tmp/.bash_aliases

    Viola! All of your aliases are now available on this machine. And, of course, you can add this command to your .bash_profile on that machine, so that it will run automatically everytime you log in.

Note: When dealing with your Unix/Linux configuration files (“dotfiles”), it is very important to pay attention to the line endings of your files. Windows and Unix/Linux use different conventions. The best way to account for this is to set the autocrlf parameter in the dotfile repository on your workstation by running:

git config core.autocrlf true