Friday, January 10, 2020

Install Java on Ubuntu

Java is a programming language used to build Android apps and real life web applications like Gmail and Google Docs. This ubiquitous language can be installed onto an Ubuntu server and its what we’ll be teaching in this tutorial today.

Pre-flight

  • Open the terminal and log in as root. If you are logged in as another user, you will need to add sudo before each command.
  • Working on a Linux Ubuntu 18.04 server
  • No installations of previous Java versions

Install Java

Step 1: Updating your system

apt-get update && apt-get upgrade

Step 2: Install the Repo

First, install the repository, its provided by a third party and you’ll need to press enter to continue downloading. The Oracle Java (JDK) Installer automatically downloads and installs Oracle JDK8.
add-apt-repository ppa:webupd8team/java
Update your system once more
apt-get update

Step 3: Install Java 8

Using the command below will kickstart the Java Installer which will assist in our task. Press Y when prompted to continue.
sudo apt install openjdk-8-jdk

Step 4: Verify the Installation of Java 8

java -version
Example Output:
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

Set Java’s Home Environment

You may be looking to set Java’s home environment once we’ve installed it onto our server. To do that, lets first, let’s find Java’s path.
update-alternatives --config java
There is 1 choice for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto mode
* 1 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode
Take the highlighted path and add the variable into your /etc/environment file. Add the JAVA_HOME path after any line that is already present.
vim /etc/environment
Once you are in the file type `i` to insert the needed line:
JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre/bin/java"
Save and exit the file by typing `ESC` followed by `:wq` and press `Enter`. Afterward, use the source command to have the system recognize the changes in your file.
source /etc/environment
You’ll know the variable has been set correctly by calling the variable.
echo $JAVA_HOME
Example Output:
root@1804:~$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle/jre/bin/java

Reference:




Thursday, January 9, 2020

How to Install, Start, Stop & Restart PostgreSQL Server on Windows, Linux, MacOS / OSX


In this post, we are going to figure out how to start, stop, and restart a PostgreSQL server on macOS, Linux, and Windows.
1. On macOS
If you installed PostgreSQL via Homebrew:
  • To start manually:
pg_ctl -D /usr/local/var/postgres start
  • To stop manually:
pg_ctl -D /usr/local/var/postgres stop
  • To start PostgreSQL server now and relaunch at login:
brew services start postgresql
  • And stop PostgreSQL:
brew services stop postgresql

If you want a hassle-free way to manage the local PostgreSQL database servers, use DBngin. It’s just one click to start, another click to turn off. No dependencies, no command line required, multiple drivers, multiple versions and multiple ports. And it’s free.

2. On Windows
Download and install PostgreSQL with Installer or Portable.
First, you need to find the PostgreSQL database directory, it can be something like C:\Program Files\PostgreSQL\10.4\data. Then open Command Prompt and execute this command:
pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" start
  • To stop the server
pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" stop
  • To restart the server:
pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" restart
Another way:
  • Open Run Window by Winkey + R
  • Type services.msc
  • Search Postgres service based on version installed.
  • Click stop, start or restart the service option.

3. On Linux
Update and install PostgreSQL 10.4
sudo apt-get update
sudo apt-get install postgresql-10.4
By default, the postgres user has no password and can hence only connect if ran by the postgres system user. The following command will assign it:
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
sudo -u postgres psql -c "CREATE DATABASE testdb;"
  • Start the PostgreSQL server
sudo service postgresql start
  • Stop the PostgreSQL server:
sudo service postgresql stop

Need a good GUI tool for PostgreSQL on MacOS and Windows? TablePlus is a modern, native tool with an elegant GUI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more.


Reference :


Sunday, December 15, 2019

Install Java on CentOS

In this tutorial, we’ll be showing you how to install Oracle’s Java 8 programming language specifically onto a CentOS 7 server. This simple object-oriented language is used for many of the applications and websites you come across today.  Let’s jump right in!

Pre-flight

  1. Open the terminal and login as root.  If you are logged in as another user, you will need to add sudo before each command.
  2. Working on a Linux CentOS 7 server
  3. No installations of previous Java versions

Installing Java 8 on CentOS 7

Step 1: Update

As a matter of best practice we’ll update before installing any new programs:
yum -y update

Step 2: Install Java 8

yum install java-1.8.0-openjdk

Step 3:  Verify Java is Installed

java -version
Example Output:
java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

Set Java’s Home Environment

Step 1: Find Java’s Path

Let’s set the JAVA_HOME variable, using the following command will give us a path so we can set the variable.
update-alternatives --config java
You’ll see a prompt to “Enter to keep the current selection[+], or type selection number:”, if you had multiple Java version you could set the default here, but all we need is the path of Java so we can exit pressing enter.  The highlighted area is the path we will need to copy/paste into our .bash_profile file.
There is 1 choice for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto mode
* 1 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode

Step 2: Setting Java’s Path in Your Environment

After copying your Java’s path, open the .bash_profile with your text editor.
vim .bash_profile
Export your Java path into the .bash_profile by adding the following to the bottom of the file. (Your path may look different from mine, and it’s not important that they vary.)
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre/bin/java
Refresh the File:
source .bash_profile
When you use the JAVA_HOME variable you’ll now be able to see the path you set.
echo $JAVA_HOME
Example Output:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre/bin/java

Reference: