How to Build a Xubuntu Erlang PostgreSQL Dev Box - comptekki/dbswui GitHub Wiki

How to build a Xubuntu dev box for Erlang/PostgreSQL/Web Development

Xubuntu

Download Xubuntu iso:

http://xubuntu.org/getxubuntu/

Create boot CD/DVD/USB-stick Install Xubuntu As it reboots, unplug the network cable When it is booted and you are logged in, click the Applications Menu, Accessories, Terminal Emulator and enter:

sudo ufw enable

to turn the firewall on. I like gufw also (gui for ufw). If you want that, enter this in the terminal:

sudo apt-get install gufw

When the firewall is enabled, plug the network cable back in.

To create an application launcher for gufw, right-click the desktop and select Create Launcher, type in fire and select Create Launcher Firewall.... This will create an icon on the desktop for gufw. You can also create application launchers in the Application Menu by clicking the Application Menu, Settings Manager, Main Menu.

Erlang

Download Erlang from https://erlang.org

wget http://www.erlang.org/download/otp_src_R15B03-1.tar.gz

While it is downloading run these commands to prepare for configuring Erlang:

sudo apt-get install g++ autoconf xsltproc libncurses5-dev unixodbc-dev fop openjdk-7-jdk libssl-dev libwxgtk2.8-dev libqt4-opengl-dev libgtk2.0-dev

In a terminal run these commands after Erlang has finished downloading:

mkdir src
cd src
tar -zxf ~/Downloads/otp_src_R15B02.tar.gz
cd otp_src_R15B02
./otp_build autoconf
./configure
make
sudo make install

Now run erl on the command line then run the wx widgets demo: $ erl Erlang R15B02 (erts-5.9.2) [source] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.9.2  (abort with ^G) 
1> wx:demo().

you should now get the wx widgets demo to start up.

To get out of the erlang vm, press ctrl-c twice

wx widgets is good to have as it allows you to do some debugging in the erlang vm

to debug in the erlang vm, type these commands:

c(t, [debug_info]).
  (where t is a module name, i.e. t.erl must exist)
im().
ii(t).
iaa([init]).

Then if you have a function in t.erl called test you can run:

t:test().

and start visually debugging the code.

Chrome

Install chrome web browser by going to:

http://www.google.com/chrome

and download.

The file should downloaded in to ~/Downloads. Open the folder by double-clicking the Home icon and then the Downloads folder. Double-click the chrome .deb file and click Install in Ubuntu Software Center. Or on the command line run:

sudo dpkg -i google-chrome-stable_current_i386.deb

Emacs

In a terminal, enter:

sudo apt-get install emacs23-nox

If you want the gui emacs, enter:

sudo ap-get install emacs23

Erlang mode in Emacs

http://www.erlang.org/doc/apps/tools/erlang_mode_chapter.html

Erlang mode reference manual

http://www.erlang.org/doc/man/erlang.el.html

Git

In a terminal, enter:

sudo apt-get install git

Git in Emacs

To get git integration in to emacs, type this:

sudo apt-get install git-el

Emacs config file

I use these commands in an ~/.emacs file:

;erlang 15b02
(setq load-path (cons  "/usr/local/lib/erlang/lib/tools-2.6.8/emacs"
	 load-path))
	 (setq erlang-root-dir "/usr/local/lib/erlang")
	 (setq exec-path (cons "/usr/local/lib/erlang/bin" exec-path))
(require 'erlang-start)

; define function to shutdown emacs server instance
(defun ked ()
  "Save buffers, Quit, and Shutdown (kill) server"
  (interactive)
   (save-some-buffers)
  (kill-emacs)
)

(setq default-tab-width 4)

(global-set-key (kbd "ESC <up>") 'scroll-down)
(global-set-key (kbd "ESC <down>") 'scroll-up)

(global-set-key (kbd "ESC <left>") 'previous-buffer)
(global-set-key (kbd "ESC <right>") 'next-buffer)

(global-set-key "\M-n" 'previous-buffer) ; [M]-[n]
(global-set-key "\M-N" 'next-buffer) ; [M]-[N]

(put 'upcase-region 'disabled nil)

PostgreSQL

Download latest from:

http://www.postgresql.org/ftp/source/

Open a terminal and cd to Downloads Enter these commands (depending on what version you have):

It’s good to have the readline library installed before configuring postgresql:

sudo apt-get install libreadline6-dev

Next in terminal....

	 cd Downloads
	 tar -jxf postgresql-9.2.1.tar.bz2
	 cd postgresql-9.2.1
	 ./configure
	 make
	 sudo make install

If you are curious about how long it takes to run “make” here or how long any other command takes to run, enter time before the command:

time make

Add /usr/local/psql/bin to your path in .bashrc

export PATH=/usr/local/pgsql/bin:$PATH

and add the LC_ALL environment variable below to .bashrc to set the C locale for all LC_ environments:

export LC_ALL=C

Create initial postgres data area

cd /usr/local
mkdir pgdata
sudo chown some_username pgdata
# force local to C, create initial db with user postgres
# and prompt for password in folder pgdata
initdb --local=C -U postgres -W pgdata  

Start postgres:

Use either of these commands:

postgres -D data

i.e.:

postgres -D /usr/local/data

or

pg_ctl -D data -l logfile start

Create database:

createdb -U postgres dbooks

If you run createdb with your console user, you can add a postgres user and grant privileges like this:

create user postgres with password 'pguser';
grant all privileges on database dbooks to postgres;
grant all privileges on table dbooks to postgres;
grant all privileges on table dbooks_id_seq to postgres;

Add data to dbooks database

Enter the following on the command-line: (sample data found in the sample-data folder on github repo)

psql -U postgres dbooks
\i dbooks.sql

Open a shell and type these commands:

cd /usr/local/src
git clone https://github.com/comptekki/dbswui.git
cd dbswui
make

If you don't do the above commands in /usr/local/src, then you need to edit include/db.hrl and change the CONF path to the correct location.

run dbswui by executing start stript on command line:

./start.sh

Run a browser and go to:

http://localhost:7080/db

or:

https://localhost:7443/db

or to add/delete/update records:

https://localhost:7443/db/edit

Editing requires a username and password. Both are test for testing purposes. These values may be changed in dbswui/src/db.conf

Bash aliases and variables

alias l='ls -al'
alias le='ls -ale'
alias ll='ls -al|less'
alias rm='rm -i'
alias mv='mv -i'
alias cp='cp -i'
alias vib='vi ~/.bashrc'
alias bs='. ~/.bashrc'
alias h='history'
alias c='tput clear'
alias ..='cd ..'
alias crl='curl -C - -O'
alias ce='crontab -e'
alias p='python'
alias s='sudo su -'

alias gbd='git branch -d'
alias gbm='git branch -m'
alias gc='git commit -am'
alias gch='git checkout'
alias gcm='git checkout master'
alias gl='git log'
alias glh='git log|head'
alias gm='git merge --no-ff'
alias gmd='git merge dev'
alias gp='git push'
alias gpd='git push origin dev'
alias gpt='git push --tags'
alias gr='git reflog'
alias grh='git reflog|head'
alias gs='git status'
alias gt='git tag -am'
alias gup='git log origin/master..master'

alias e='emacsclient -nw'
alias eb='e ~/.bashrc'
alias ee='e ~/.emacs'
alias emd='emacs --daemon'
alias pse='ps -ax|grep "emacs --daemon"'
alias ke="emacsclient -e '(kill-emacs)'"

export GIT_AUTHOR_EMAIL='[email protected]'
export GIT_AUTHOR_NAME='my_name'
export EDITOR='emacs'
export VISUAL='emacs'

How to turn off middle button paste: (from http://jaredrobinson.com/blog/howto-disable-middle-mouse-paste-in-linux/)

Run the following command:

xmodmap -e "pointer = 1 25 3 4 5 6 7 8 9"

To persist this behavior, edit ~/.Xmodmap and add

pointer = 1 25 3 4 5 6 7 8 9

Other Erlang build help

Install kerl:

  $> git clone https://github.com/yrashk/kerl.git

Use kerl:

  $> kerl build git https://github.com/erlang/otp OTP-17.3.4 17.3.4

Find build in:

  $> cd ~/.kerl/builds/17.3.4/otp_src_git
⚠️ **GitHub.com Fallback** ⚠️