Tuesday, June 2, 2015

How to use multiple versions of GCC/G++

In programming life we may require to install and use multiple versions of the compiler on the same system. For an example, to support for C++11 features gcc/g++ v4.7 or later version is requried and for legacy codes which do not require new features, gcc/g++ v4.6 or below is required.

I'm using Ubuntu 14.04.2 LTS and gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 is the default compiler and the importent thing is it only includes the 'C' compiler, not the 'C++' compiler. As the first step I installed build-essential package using following command,
$ sudo apt-get install build-essential
This gave the expected C++ compiler.

I installed the gcc v4.6 and g++ v4.6 to use as my legacy code compiler using the following command
$ sudo apt-get install gcc-4.6 g++-4.6
Once succesfully installed them, system contains two different versions of C/C++ compilers. Create symbolic links by using update-alternatives keep the record of 2 C/C++ compiler as follows.

$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 10 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
From this point on-words, When required to switch compilers between v4.6 and v4.8 following command can be used
$ sudo update-alternatives --config gcc

Friday, October 11, 2013

Install a software in Ubuntu from a PPA

A new software or a new version of a software is released, it is not available in repos of Ubuntu and have to wait until the next release of Ubuntu to try it. But most of the latest software releases are available as PPAs (Personal package archives) in Launchpad and it helps to Ubuntu users to install and try up-to-date versions of software.

A PPA, or Personal Package Archive, is a collection of software not included in Ubuntu by default. It might be an unreleased piece of software which is provided by the community. Therefore user should be aware of the possible risks before adding a PPA.

Here we are going consider the example of “Twisted-dev” Team, which provides PPA of the latest Twisted Development releases. (Twisted is an event-driven networking engine written in Python)

Visit the PPAs overview page in Launchpad and copy the PPA's location which is mentioned under “Adding this PPA to your system” heading. In this example PPA location is ppa:twisted-dev/ppa. You can find Twisted's PPAs overview page in here. Now, run the following command with the PPA's location.
$ sudo add-apt-repository ppa:twisted-dev/ppa
After running above command your sytem will fetch the PPA’s key. This will let your Ubuntu system verify that the packages in the PPA have not been interfered since they were built.

Run the following command to download the latest list of softwares form the each repos that system knows. Including the Twisted PPA.
$ sudo apt-get update
Now all sets to start installing software from the PPA. Use the regular apt-get install or synaptic to download and install it. If the added PPA is for an already installed package, run following command to upgrade it to most recent version.
$ sudo apt-get dist-upgrade
Enjoy the latest version of Twisted or the software have been installed from the PPA!

Saturday, September 28, 2013

Create EC2 Apache Stratos AMI

Apache Stratos is an open source Platform as a Service (PaaS) cloud platform and it could be installed on a single node or on multiple nodes. The single node installation could be used for development and demonstration purposes. Here we are going to create EC2 Apache Stratos AMI for demonstration purpose.

You can simply create your own EC2 AMI for Apache Stratos by following the below steps.

Step 1: Create Instance

Create new instance of prefered Linux server distribution on EC2.
I have used Ubuntu Server 12.04.2 LTS (ami-64084736) and m1.large as instance type.

Step 2: Install prerequisites

To setup the instance for Apache Stratos, have to install following software.
  1. Java 1.6.x (Oracle JDK/JRE)
  2. git 
  3. MySQL Server
  4. zip
  5. Gitblits (Optional). Follow the steps mentioned below to enable the internal Git repository service 

Step 3: Configure Apache Stratos 

Create new folders for below purposes.
  • Folder to store stratos setup : <setup-path> (/opt/stratos-installer)
  • Folder to store the binary distributions : <stratos-pack-path>  (/opt/stratos-packs)
  • Folder which stratos will be installed : <stratos-path>  (/opt/stratos)
Build Apache Stratos from source
$ git clone https://git-wip-us.apache.org/repos/asf/incubator-stratos.git
$ git checkout -b 3.0.0-incubating-rc4 3.0.0-incubating-rc4
$ cd incubator-stratos
$ mvn clean install

Copy /tools/stratos-installer into <setup-path> folder and update configuration parameters in conf/setup.conf file accordingly. Example is shown below.

# General configuration
# ----------------------------------------------------------------------------
export setup_path=/opt/stratos-installer #Folder path containing stratos_setup
export stratos_pack_path=/opt/stratos-packs #Folder path containing stratos packages 
export stratos_path=/opt/stratos #Folder which stratos will be installed
 
export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_45 #Java home path

Download Cloud Controller, Stratos Controller, Elastic Load Balancer, Stratos Agent packages from https://dist.apache.org/repos/dist/dev/incubator/stratos/3.0.0-incubating-rc4/ and copy to a desired location (<stratos-pack-path>)or you can use the packages which you have already built.

Download WSO2 Message Broker binary distribution from http://wso2.com and copy it to <stratos-pack-path>.Make sure to set MB's port offset in repository/conf/carbon.xml to 5. This will set the actual port to 5677

Download MySQL Java connector from http://dev.mysql.com/downloads and copy the jar file to <stratos-pack-path> and update the conf/setup.conf file accordingly.

Update configuration parameters in conf/setup.conf under  IaaS Providers section with your own cartridges, refer here for more details on creating cartridge images. I have used the pre-built PHP, MySQL and Tomcat cartridge images publicly available in Asia Pacific (Singapore) Region.
  • PHP Cartridge : ami-8a733bd8
  • MySQL Cartridge : ami-3e753d6c
  • Tomcat Cartridge : ami-6484cc36
Now you have successfully configured the Apache Stratos instance. You can create the snapshot from that instance and share it in a secure manner.

You will be able to use ami-e0b7e2b2 for the demonstration which is available in Asia Pacific (Singapore) Region