All posts by Marinko Tarlać

Oracle Java 8 on Ubuntu 14.04 / Mint 17.3

Default “Java” version of Mint Linux 17.3 (or Ubuntu 14.04) is OpenJDK 1.7 which works fine, but some SDKs won’t install until you upgrade to 1.8 (for example Tizen IDE studio complains on OpenJDK 1.7)

Before you start, check the current version with “java -version”

java version "1.7.0_121"
OpenJDK Runtime Environment (IcedTea 2.6.8) (7u121-2.6.8-1ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.121-b00, mixed mode)

Add the PPA, update and install oracle-java8-installer

sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

(During the install process you’ll need to accept the Oracle terms)

Now, check again with “java -version”

java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

In case you’re still receiving the 1.7 versions as response, install “oracle-java8-set-default” package with

sudo apt install oracle-java8-set-default

and check again.

PostgreSQL on CentOS 7 – Howto

In this post I’ll try to show you how to install PostgreSQL 9.6 on CentOS 7.3 which is the current versions of PostgreSQL and CentOS.

The default PostgreSQL version on CentOS 7.3 is PostgreSQL 9.2 which is still maintained, but in case you’re more for a “cutting edge” technology, try to follow the next steps

First, remove the already installed version (in case you installed the default version)

yum remove postgresql-server postgresql-contrib

Install official PostgreSQL Yum repo with

yum -y install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm

which will create a new repo file /etc/yum.repos.d/pgdg-96-centos.repo with the next content

[pgdg96]
name=PostgreSQL 9.6 $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-$releasever-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-96
 
[pgdg96-source]
name=PostgreSQL 9.6 $releasever - $basearch - Source
failovermethod=priority
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/9.6/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-96
 
[pgdg96-updates-testing]
name=PostgreSQL 9.6 $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/testing/9.6/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-96
 
[pgdg96-source-updates-testing]
name=PostgreSQL 9.6 $releasever - $basearch - Source
failovermethod=priority
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/testing/9.6/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-96

Now install PostgreSQL with

yum -y groupinstall "PostgreSQL Database Server 9.6 PGDG"

and initialize it with

/usr/pgsql-9.6/bin/postgresql96-setup initdb

Start and enable service with

systemctl start postgresql-9.6.service
systemctl enable postgresql-9.6.service

Switch to the postgres user with

su postgres -

and connect to the server (currently running only on localhost)

psql

Check the installed version with

SELECT version();

You should get something like

...
                                                 version                                                 
---------------------------------------------------------------------------------------------------------
 PostgreSQL 9.6.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4), 64-bit
(1 row)
....

The default PostgreSQL installation listens only on localhost so if you want to connect from the remote host you’ll need to change a few things.

Open /var/lib/pgsql/9.6/data/postgresql.conf and find the line #listen_addresses = ‘localhost’… and replace it with the listen_addresses = ‘*’

Before

#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
 
# - Connection Settings -
 
#listen_addresses = 'localhost'         # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)
max_connections = 100                   # (change requires restart)

after

#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
 
# - Connection Settings -
 
#listen_addresses = 'localhost'         # what IP address(es) to listen on;
listen_addresses = '*'
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)
max_connections = 100                   # (change requires restart)

Now open /var/lib/pgsql/9.6/data/pg_hba.conf and add at the end

host    all             all             YOUR_CLIENT_IP_ADDRESS/32            md5

save the file and restart service with

systemctl restart postgresql-9.6.service

The last step before you test it is to change the password for postgres user with

su postgres -
 
bash-4.2$ psql
psql (9.6.1)
Type "help" for help.
 
postgres=# \password
Enter new password:
Enter it again:
postgres=# \q
exit

Now add new server in pgAdmin and test it

Nginx – redirecting with a regular expression

NGINX rewrite rules are quite simple and easy to understand. They change the part or complete URL in a client request (for example in case when you want to redirect your users from http to https, to another domain/subdomain, etc)

For example, the simple redirect with code 301 (moved permanently) from olddomain.com to newdomain.com can be achieved with:

server {
    listen 80;
    listen 443 ssl;
    server_name olddomain.com www.olddomain.com;
    return 301 $scheme://www.newdomain.com$request_uri;
}

In this case, $scheme and $request_uri are nginx variables and they are used to capture and replicate the values from the original request URL ($scheme is the protocol – ‘http’ or ‘https’ and $request_uri is the portion of the URL that follows the domain name – for example ‘/getUser?id=blabla’)

Examples

To add ‘www’ before the domain:

server {
    listen 80;
    listen 443 ssl;
    server_name domain.com;
    return 301 $scheme://www.domain.com$request_uri;
}

To remove the ‘www’:

server {
    listen 80;
    listen 443 ssl;
    server_name www.domain.com;
    return 301 $scheme://domain.com$request_uri;
}

To redirect all requests which doesn’t match already defined server and location blocks to specific home page
For example subdomain whose IP address points to the server but the server doesn’t have defined server or location block for this subdomain

server {
    listen 80 default_server;
    listen 443 ssl default_server;
    server_name _;
    return 301 $scheme://www.domain.com;
}

Also, you can add $request_uri variable above.

Forcing all Requests to Use SSL/TLS

server {
    listen 80;
    server_name www.domain.com;
    return 301 https://www.domain.com$request_uri;
}

Redirecting a subdomain with a regular expression to new subdomain

server {
    listen 80;
    server_name ~^((?<subdomain>.*)\.olddomain.com)$;
    return 301 $scheme://${subdomain}.newdomain.com$request_uri;
}

Redirecting subdomain to specific dir (with a regular expression)

server {
    listen 80;
    server_name ~^((?<subdomain>.*)\.)(?<domain>[^.]+)\.(?<tld>[^.]+)$;
    return 301 $scheme://${domain}.${tld}/${subdomain};
}

Source:
https://www.nginx.com/blog/creating-nginx-rewrite-rules/
https://stackoverflow.com/questions/9578628/redirecting-a-subdomain-with-a-regular-expression-in-nginx/31037713

Change hostname on Mint Linux / Ubuntu – Howto

To change your hostname, you’ll need to edit /etc/hostname file with

sudo nano /etc/hostname

The file content is very simple. It contains the current hostname and all you need to do is to replace it with the new one, save and exit

After you save the changes, open /etc/hosts file and replace the current hostname with the new one near 127.0.1.1 IP address.

Change

...
127.0.1.1 old-hostname
...

into

...
127.0.1.1 new-hostname
...

Save file and exit.

Now, enter the next command

sudo hostname new-hostname

Your computer’s hostname will be changed immediately. (The change won’t appear in the terminal until you reopen it again)

This method will work on all Debian based distros (Ubuntu, Kubuntu, ….)

Cx UI framework

If you’re working on a new admin and dashboard application and you’re looking for a quality UI framework which is fast and easy to use, check the Cx. It is inspired by React, Redux, Ext JS, Angular and other open-source libraries and frameworks, but as they said, it tries to cover all you need for a modern web app.

During the promo period, you can buy it with 50% discount (coupon code: LAUNCH-PARTY). For more information, please visit the official page – https://cx.codaxy.com/.

cx-starter

Command line system information

If you’re not sure which components are installed in your server/pc, you can use inxi which is a command line system information script. It will show you the system hardware, CPU, drivers, Xorg, Desktop, Kernel, GCC version(s), Processes, RAM usage, and a wide variety of other useful information.

For example:

myPC@myPC ~ $ inxi -F
System:    Host: myPC Kernel: 3.19.0-32-generic x86_64 (64 bit) Desktop: Cinnamon 2.8.8
           Distro: Linux Mint 17.3 Rosa
Machine:   System: LENOVO product: 20E1000BSC v: ThinkPad W550s
           Mobo: LENOVO model: 20E1000BSC v: SDK0E50510 WIN Bios: LENOVO v: N11ET34W (1.10 ) date: 08/20/2015
CPU:       Dual core Intel Core i7-5600U (-HT-MCP-) cache: 4096 KB 
           clock speeds: max: 3200 MHz 1: 901 MHz 2: 981 MHz 3: 2195 MHz 4: 2199 MHz
Graphics:  Card-1: Intel Broadwell-U Integrated Graphics
           Card-2: NVIDIA GM108GLM [Quadro K620M]
           Display Server: X.Org 1.17.1 drivers: nvidia (unloaded: intel)
           Resolution: 1920x1080@59.9hz, 1920x1080@60.0hz
           GLX Renderer: Quadro K620M/PCIe/SSE2 GLX Version: 4.5.0 NVIDIA 352.63
Audio:     Card-1 Intel Wildcat Point-LP High Definition Audio Controller driver: snd_hda_intel
           Card-2 Intel Broadwell-U Audio Controller driver: snd_hda_intel
           Sound: Advanced Linux Sound Architecture v: k3.19.0-32-generic
Network:   Card-1: Intel Ethernet Connection (3) I218-LM driver: e1000e
           IF: eth0 state: up speed: 1000 Mbps duplex: full mac: 54:ee:75:cc:11:4a
           Card-2: Intel Wireless 7265 driver: iwlwifi
           IF: wlan0 state: up mac: 18:5e:0f:ee:f8:aa
Drives:    HDD Total Size: 768.2GB (17.1% used) ID-1: /dev/sda model: LITEON_LCH size: 512.1GB
           ID-2: /dev/sdb model: ADATA_SP600NS34 size: 256.1GB
Partition: ID-1: / size: 28G used: 9.4G (37%) fs: ext4 dev: /dev/sdb1
           ID-2: /home size: 195G used: 60G (33%) fs: ext4 dev: /dev/sdb3
RAID:      No RAID devices: /proc/mdstat, md_mod kernel module present
Sensors:   System Temperatures: cpu: 50.0C mobo: N/A gpu: 48C
           Fan Speeds (in rpm): cpu: 2466
Info:      Processes: 229 Uptime: 1:09 Memory: 2341.5/15748.3MB Client: Shell (bash) inxi: 2.2.28

Install FreeRADIUS – talloc library not found

In case you’re trying to install FreeRadius 3 on the latest CentOS (currently 6.8), there is a chance you’ll see the next error

...
checking for _talloc in -ltalloc in /opt/lib... no
configure: WARNING: talloc library not found. Use --with-talloc-lib-dir=<path>.
configure: error: FreeRADIUS requires libtalloc
...

To fix this problem, simple install libtalloc-devel package with

yum install libtalloc-devel

Disable bluetooth on startup – howto

I’m using Mint Linux and I noticed that the Bluetooth adapter is always on (I turned it off in the previous  session). I’m using Bluetooth from time to time, but I don’t like to see it on when I don’t need it. Besides, it wastes battery.

You can turn it off per session (as I did), but next time it’s right back on which annoys me.  As I can see, I’m not the only one who is affected with this.

The solution is set InitiallyPowered parameter to false.

sudo nano /etc/bluetooth/main.conf

Search for the entry:

InitiallyPowered = true

and change the value to:

InitiallyPowered = false

Next time you boot, it should be down.

In case this doesn’t help, try to turn off bluetooth service by adding “/etc/init.d/bluetooth stop” inside /etc/rc.local file (before the “exit 0” line)

Fix “Failed To Fetch” Apt error Howto

Google announced plans to discontinue 32-bit Google Chrome for Linux and it has. On some 64bit Ubuntu based systems (Mint/Kubuntu/Xubuntu,..), during update process you may notice the next error:

“Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/Release Unable to find expected entry ‘main/binary-i386/Packages’ in Release file (Wrong sources.list entry or malformed file)”

To fix this error you’ll need to make some changes in google-chrome.list

Open /etc/apt/sources.list.d/google-chrome.list file and add [arch=amd64] before “http”

deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main

Do not edit or replace any other text in this file. Save the changes and refresh your package list with

sudo apt-get update

The “failed to fetch” APT error should no longer appear