Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

How To Install and Use LinuxBrew on a Linux VPS

Intro

LinuxBrew is a Linux-fork of the popular Mac OS X HomeBrew package manager.
LinuxBrew is package-management-software, which enables installing packages from source, on top on the system's default package management (e.g. "apt/deb" in Debian/Ubuntu and "yum/rpm" in CentOS/RedHat).

Why Use LinuxBrew ?

  • HomeBrew was originally developed for Mac OS X (which does not have a standard open-source package-management system). It superceded package-managements such as MacPorts and Fink. LinuxBrew is homebrew ported to Linux.
  • Most Linux distributions have a good package management system (e.g. "apt/deb" in Debian/Ubuntu and "yum/rpm" in CentOS/RedHat), however
    • Packages in the standard repositories are often older than the latest available versions, and
    • Many open-source packages are not available in the standard repositories (e.g. common bioinformatics tools).
  • LinuxBrew provides a repository of software installation recipes (packages are installed from source and compiled on the local machine) to complement the packages from the distribution's standard repository.
  • LinuxBrew provides an easy method to build your own repositories (i.e. list of open-source packages tailored to your needs).
  • LinuxBrew installs software in user-specified directory (not system-wide), and does not require sudo access.
  • LinuxBrew (and HomeBrew) integrates very well with GitHub, enabling sharing of installation recipes easily.
Especially with DigitalOcean, which (at the time of this writing) does not provide sharable Droplet Images (with custom-configured installed software), a LinuxBrew repository can provide a quick method to install specific packages and versions on a standard Linux machine.

The Gist of LinuxBrew

Simply put, LinuxBrew takes care of downloading the tar.gz file and running ./configure && make && make install for you (or whichever commands are needed to install the package).
A LinuxBrew Formula is a Ruby script which defines where to find the tar.gz file, how to build the package, and how to install it.
A formula file can be as simple as hmmer.rb (a bioinformatics tool):
class Hmmer < Formula
  homepage 'http://hmmer.janelia.org/'
  url 'http://selab.janelia.org/software/hmmer3/3.1b1/hmmer-3.1b1.tar.gz'

  def install
    system "./configure", "--prefix=#{prefix}"
    system "make"
    system "make install"
  end
end
Or as complicated as emacs.rb.
Once a formula file is properly defined, installing the package is simply a matter of running:
$ brew install FORMULA

Preparing for LinuxBrew - Debian/Ubuntu

For Debian/Ubuntu-based systems, run the following commands:
$ sudo apt-get update
$ sudo apt-get upgrade -y
$ sudo sudo apt-get install -y build-essential make cmake scons curl git \
                               ruby autoconf automake autoconf-archive \
                               gettext libtool flex bison \
                               libbz2-dev libcurl4-openssl-dev \
                               libexpat-dev libncurses-dev

Preparing for LinuxBrew - CentOS/RedHat

For RedHat/CentOS-based systems, run the following commands:
$ sudo yum update -y
$ sudo yum groupinstall -y "Development Tools"
$ sudo yum install -y \
        autoconf automake19 libtool gettext \
        git scons cmake flex bison \
        libcurl-devel curl \
        ncurses-devel ruby bzip2-devel expat-devel

Installing LinuxBrew

Installing LinuxBrew is simply a matter of cloning the LinuxBrew Repository.

Step 1 - Clone LinuxBrew

To keep things tidy, clone LinuxBrew into a hidden directory in the user's home directory:
$ git clone https://github.com/Homebrew/linuxbrew.git ~/.linuxbrew
But any other directory would work just as well.

Step 2 - Update environment variables

The next step is to add LinuxBrew to the user's environment variables.
Add the following lines to the end of the user's ~/.bashrc file:
# Until LinuxBrew is fixed, the following is required.
# See: https://github.com/Homebrew/linuxbrew/issues/47
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib64/pkgconfig:/usr/share/pkgconfig:$PKG_CONFIG_PATH
## Setup linux brew
export LINUXBREWHOME=$HOME/.linuxbrew
export PATH=$LINUXBREWHOME/bin:$PATH
export MANPATH=$LINUXBREWHOME/man:$MANPATH
export PKG_CONFIG_PATH=$LINUXBREWHOME/lib64/pkgconfig:$LINUXBREWHOME/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=$LINUXBREWHOME/lib64:$LINUXBREWHOME/lib:$LD_LIBRARY_PATH
NOTE: If you installed LinuxBrew to a different directory, change the path in LINUXBREWHOME above.

Step 3 - Test installation

To ensure those changes take effect, log-out and log-in again. The shell should then use these new settings.
To test these new settings, try:
$ which brew
/home/ubuntu/.linuxbrew/bin/brew
$ echo $PKG_CONFIG_PATH
/home/ubuntu/.linuxbrew/lib64/pkgconfig:/home/ubuntu/.linuxbrew/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib64/pkgconfig:/usr/share/pkgconfig:

Installing Packages with LinuxBrew

Which packages are available?

Type brew search to see the list of all available packages (all the packages that the current installation of LinuxBrew knows about – see below about adding repositories).
Type brew search WORD to see all the packages (called Formulas in HomeBrew jargon) which contain WORD. Example:
$ brew search xml
blahtexml       libnxml   libxml2     xml-coreutils   xml2        xmlrpc-c
html-xml-utils  libwbxml  libxmlsec1  xml-security-c  xmlcatmgr   xmlsh
libmxml         libxml++  tinyxml     xml-tooling-c   xmlformat   xmlstarlet

Install a package

To install a package, run brew install PACKAGE.
Example, installing jq - JSON processor:
$ brew install jq
==> Downloading http://stedolan.github.io/jq/download/source/jq-1.3.tar.gz
==> ./configure
==> make
/home/ubuntu/.linuxbrew/Cellar/jq/1.3: 7 files, 256K, built in 10 seconds
$ which jq
/home/ubuntu/.linuxbrew/bin/jq
$ jq --version
jq version 1.3
LinuxBrew's usefulness is apparent: While Ubuntu has jq in the latest repositories, its version is old (1.2). Debian Stable and Testing don't have jq package at all. LinuxBrew's version is the most recent one (1.3). Addionally, LinuxBrew installs the program to a path which will not conflict with the system's default location.

Adding Existing HomeBrew Repositories

HomeBrew/LinuxBrew repositories are called TAPS. These are simply GitHub repositories containing Ruby scripts ('Formulas'). The HomeBrew Githab User has several common repositories.
Example: adding the homebrew-science repository (containing many useful open-source scientific programs) and the HomeBrew-Games repository:
$ brew tap homebrew/science
Cloning into '/home/ubuntu/.linuxbrew/Library/Taps/homebrew-science'...
Tapped 237 formula
$ brew tap homebrew/games
Cloning into '/home/ubuntu/.linuxbrew/Library/Taps/homebrew-games'...
Tapped 57 formula
List available taps:
$ brew tap
homebrew/science
homebrew/games
Install any package from those repositories:
$ brew install gnu-go
==> Downloading http://ftpmirror.gnu.org/gnugo/gnugo-3.8.tar.gz
#################################################################
==> ./configure --prefix=/home/ubuntu/.linuxbrew/Cellar/gnu-go/3.8 --with-readline=/usr/lib
==> make install
/home/ubuntu/.linuxbrew/Cellar/gnu-go/3.8: 9 files, 7.0M, built in 60 seconds

Updating TAPs and Packages

To download any updates to Formulas, run:
$ brew update
To upgrade packages (if updates are available), run:
$ brew upgrade PACKAGE

Creating Custom/Private TAPs (Repositories)

A HomeBrew TAP/Repository is simply a collection of Formulas – Ruby scripts stored in local files or in GitHub repositories.

Formulas in local files

To install a formula from a local file, run:
$ brew install /full/path/to/file.rb
This is useful when creating (and debugging) a new formula.

Formulas in GitHub repositories

To create a custom TAP repository in github, Create a new GitHub repository (in your user's github account) and name it homebrew-NAME. It must start with 'homebrew-' to work as a HomeBrew/LinuxBrew tap. NAME can be any name you want.
Example:
GitHub user agordon has a HomeBrew repository named gordon, the full URL is: https://github.com/agordon/homebrew-gordon.
To use this repository ("tap it"):
$ brew tap agordon/gordon
Cloning into '/home/ubuntu/.linuxbrew/Library/Taps/agordon-gordon'...
Warning: Could not tap agordon/gordon/libestr over Homebrew/homebrew/libestr
Warning: Could not tap agordon/gordon/coreutils over Homebrew/homebrew/coreutils
Tapped 12 formula
NOTES
  1. brew tap used the username agordon and the repository suffix gordon (suffix of 'homebrew-gordon') and deduced the github URL to access.
  2. Formulas in custom repostiries can conflict with formulas in the official HomeBrew repositories. That is perfectly normal. See below on how to install such packages.
To install non-conflicting packages from custom repositories, run:
$ brew install libjson
To install packages from specific taps, run:
$ brew install agordon/gordon/coreutils

Source from https://www.digitalocean.com

How INSTALL JAVA and Set JAVA PATH in ubuntu



1.To install java , go to terminal and enter

sudo apt-get install openjdk-7-jdk

once you done the Installation


2.GO to Terminalto edit .bashrc file

vi ~/.bashrc

[if not allowing to edit you have to give the root permission by type “sudo”]

sudo vi ~/.bashrc


It will open the Text editor

3. Add this code to end of the Document
4.


JAVA_HOME=/usr/lib/jvm/jdk1.7.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export
   JAVA_HOME
export
   JRE_HOME
   export PATH
Save the file 
4.To check whether the PATH is set properly 
Type JAVA -version
if you got like
this , PATH has beed set successfully 
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.5)
(7u79-2.5.5-0ubuntu0.14.04.2)
OpenJDK Server VM (build 24.79-b02, mixed mode)

How To Use SSH to Connect to a Remote Server in Ubuntu

What Is SSH?

One essential tool to master as a system administrator is SSH.
SSH, or Secure Shell, is a protocol used to securely log onto remote systems. It is the most common way to access remote Linux and Unix-like servers, such as VPS instances.
In this guide, we will discuss how to use SSH to connect to a remote system.

Basic Syntax

The tool on Linux for connecting to a remote system using SSH is called, unsurprisingly, ssh.
The most basic form of the command is:
ssh remote_host
The remote_host in this example is the IP address or domain name that you are trying to connect to.
This command assumes that your username on the remote system is the same as your username on your local system.
If your username is different on the remote system, you can specify it by using this syntax:
ssh remote_username@remote_host
Once you have connected to the server, you will probably be asked to verify your identity by providing a password.
Later, we will cover how to generate keys to use instead of passwords.
To exit back into your local session, simply type:
exit

How Does SSH Work?

SSH works by connecting a client program to an ssh server.
In the above commands, ssh is the client program. The ssh server is already running on the remote_hostthat we specified.
In your VPS, the sshd server should already be running. If this is not the case, click on the Console Accessbutton from your droplet page:
DigitalOcean Console Button
You will be presented with a login screen:
DigitalOcean Console Screen
Log in with your credentials.
The process needed to start an ssh server depends on the distribution of Linux that you are using.
On Ubuntu, you can start the ssh server on the VPS by typing:
sudo service ssh start
That should start the sshd server and you can then log in remotely.

How To Configure SSH

When you change the configuration of SSH, you are changing the settings of the sshd server.
In Ubuntu, the main sshd configuration file is located at /etc/ssh/sshd_config.
Back up the current version of this file before editing:
sudo cp /etc/ssh/sshd_config{,.bak}
Open it with a text editor:
sudo nano /etc/ssh/sshd_config
You will want to leave most of the options in this file alone. However, there are a few you may want to take a look at:
Port 22
The port declaration specifies which port the sshd server will listen on for connections. By default, this is 22.
It may be a good idea to change this to a non-standard port to help obscure your server from random port scans. If you do change your port, we will show you how to connect to the new port later on.
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
The host keys declarations specify where to look for global host keys. We will discuss what a host key is later.
SyslogFacility AUTH
LogLevel INFO
These two items indicate the level of logging that should occur.
If you are having difficulties with SSH, increasing the amount of logging may be a good way to discover what the issue is.
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
These parameters specify some of the login information.
LoginGraceTime specifies how many seconds to keep the connection alive without successfully logging in.
It may be a good idea to set this time just a little bit higher than the amount of time it takes you to log in normally.
PermitRootLogin selects whether root is allowed to log in.
In most cases, this should be changed to "no" when you have created user account that has access to elevated privileges (through su or sudo) and can log in through ssh.
strictModes is a safety guard that will refuse a login attempt if the authentication files are readable by everyone.
This prevents login attempts when the configuration files are not secure.
X11Forwarding yes
X11DisplayOffset 10
These parameters configure an ability called X11 Forwarding. This allows you to view a remote system's graphical user interface (GUI) on the local system.
This option must be enabled on the server and given with the client during connection with the "-X" option.
If you changed any settings in this file, make sure you restart your sshd server to implement your modifications:
sudo service ssh restart
You should thoroughly test your changes to ensure that they operate in the way you expect.
It may be a good idea to have a few sessions active when you are making changes. This will allow you to revert the configuration if necessary.
If you run into problems, remember that you can log in through the Console Access button on your droplet page.

How To Log Into SSH with Keys

While it is helpful to be able to log in to a remote system using passwords, it's often a better idea to set upkey-based authentication.

How Does Key-based Authentication Work?

Key-based authentication works by creating a pair of keys: a private key and a public key.
The private key is located on the client machine and is secured and kept secret.
The public key can be given to anyone or placed on any server you wish to access.
When you attempt to connect using a key-pair, the server will use the public key to create a message for the client computer that can only be read with the private key.
The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate.
This entire process is done in the background automatically after you set up keys.

How To Create SSH Keys

SSH keys should be generated on the computer you wish to log in from. This is usually your local computer.
Enter the following into the command line:
ssh-keygen -t rsa
Press enter to accept the defaults. Your keys will be created at ~/.ssh/id_rsa.pub and ~/.ssh/id_rsa.
Change into the .ssh directory by typing:
cd ~/.ssh
Look at the permissions of the files:
ls -l
-rw-r--r-- 1 demo demo  807 Sep  9 22:15 authorized_keys
-rw------- 1 demo demo 1679 Sep  9 23:13 id_rsa
-rw-r--r-- 1 demo demo  396 Sep  9 23:13 id_rsa.pub
As you can see, the id_rsa file is readable and writable only to the owner. This is how it should be to keep it secret.
The id_rsa.pub file, however, can be shared and has permissions appropriate for this activity.

How To Transfer Your Public Key to the Server

You can copy the public key to the remote server by issuing this command:
ssh-copy-id remote_host
This will start an SSH session, which you will need to authenticate with your password.
After you enter your password, it will copy your public key to the server's authorized keys file, which will allow you to log in without the password next time.

Client-Side Options

There are a number of optional flags that you can select when connecting through SSH.
Some of these may be necessary to match the settings in the remote host's sshd file.
For instance, you if you changed the port number in your sshd configuration, you will need to match that port on the client-side by typing:
ssh -p port_number remote_host
If you only wish to execute a single command on a remote system, you can specify it after the host like so:
ssh remote_host command_to_run
You will connect to the remote machine, authenticate, and the command will be executed.
As we said before, if X11 forwarding is enabled on both computers, you can access that functionality by typing:
ssh -X remote_host
Providing you have the appropriate tools on your computer, GUI programs that you use on the remote system will now open their window on your local system.
Source from https://www.digitalocean.com