Installing the HBase Shell for Cloud Bigtable

The HBase shell is a command-line tool that performs administrative tasks, such as creating and deleting tables. The Cloud Bigtable HBase client for Java makes it possible to use the HBase shell to connect to Cloud Bigtable.

This page describes how to install the HBase shell, along with the Cloud Bigtable HBase client for Java, on a Compute Engine instance or on your own machine. You do not need to install any other HBase dependencies, such as Apache ZooKeeper. The Cloud Bigtable HBase client for Java does not require these additional dependencies.

You can also run the HBase shell on Google Cloud Shell. See "Quickstart Using HBase Shell" for instructions.

Before you start

Before you start, you'll need to complete the following tasks:

Installing Java

To use the HBase shell with the Cloud Bigtable HBase client for Java, you must install a Java 8 runtime environment. Other versions of Java are not supported.

On Debian GNU/Linux or Ubuntu, you can install the Java 8 JRE by running the following commands:

sudo apt-get update
sudo apt-get install openjdk-8-jre-headless

For other operating systems, you can download and install the Java JRE.

Installing Maven

To run the HBase shell, you must install Apache Maven. The HBase shell uses Maven to download the required dependencies.

On Debian GNU/Linux or Ubuntu, you can install Maven by running the following commands:

sudo apt-get update
sudo apt-get install maven

On macOS, you can install Maven using Homebrew:

brew install maven

For other operating systems, see the instructions on the Maven website.

Obtaining credentials

When you install the HBase shell on your own machine, you need to obtain user access credentials for your Google Cloud Platform resources.

To obtain credentials, run the following command:

gcloud auth application-default login

The command opens your web browser. Choose your Google account if prompted, then click Allow to authorize access to your account.

Setting up the HBase shell

Downloading required files

From the command line, download and unzip the HBase shell quickstart:

curl -f -O https://storage.googleapis.com/cloud-bigtable/quickstart/GoogleCloudBigtable-Quickstart-1.0.0-pre2.zip
unzip GoogleCloudBigtable-Quickstart-1.0.0-pre2.zip

The HBase shell files are unzipped to a quickstart directory.

Setting the JAVA_HOME environment variable

Your shell's JAVA_HOME environment variable should be set to the location where your Java runtime environment is located.

To find the current value of JAVA_HOME:

echo ${JAVA_HOME}

If this command does not print any output, the variable is not set.

To set the value on Debian or Ubuntu:

export JAVA_HOME=$(update-alternatives --list java | tail -1 | sed -E 's/\/bin\/java//')

A typical value on Debian or Ubuntu is /usr/lib/jvm/java-8-openjdk-amd64/jre.

To set the value on macOS (requires Xcode's command-line tools):

export JAVA_HOME=$(/usr/libexec/java_home)

A typical value on macOS is /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home.

After you set the value of JAVA_HOME, run the following command to ensure that the value refers to the appropriate Java version:

${JAVA_HOME}/bin/java -version

Connecting to a Cloud Bigtable instance

You can use the HBase shell to connect to your Cloud Bigtable instance, get information about your existing tables, and create new tables.

To start the HBase shell, run the following command from the quickstart directory:

./quickstart.sh

If your project has only one Cloud Bigtable instance, the HBase shell will automatically connect to that instance. If your project has multiple Cloud Bigtable instances, the HBase shell will display a list of instance IDs; type the number next to your instance ID, then press Enter.

After the HBase shell connects to your instance, it displays a series of log messages, which is normal. The shell prompt then appears:

hbase(main):001:0>

Now that you've started the HBase shell, try running the following commands:

  • To list your tables, type list and press Enter. If you haven't created any tables yet, the HBase shell displays a message similar to the following:

    TABLE
    0 row(s) in 1.3580 seconds
    
    => []
    
  • To create a table, use the create command. For example, to create a table named my-table, with one column family named cf1:

    create 'my-table', 'cf1'
    

    The shell displays a message similar to the following:

    0 row(s) in 1.5210 seconds
    
    => Hbase::Table - my-table
    
  • To add data to a table, use the put command. For example, to put the value test-value in the row r1, using the column family cf1 and the column qualifier c1:

    put 'my-table', 'r1', 'cf1:c1', 'test-value'
    

    You can then use the scan command to scan the table and read the data you added:

    scan 'my-table'
    

    The shell displays output similar to the following:

    ROW      COLUMN+CELL
     r1      column=cf1:c1, timestamp=1430687836046, value=test-value
    1 row(s) in 0.6260 seconds
    
  • To drop a table, use the disable command to disable the table, followed by the drop command. For example, to drop the table my-table:

    disable 'my-table'
    drop 'my-table'
    
  • To exit the HBase shell, type exit and press Enter.

While the HBase shell is running, you can type help to get usage instructions. See the HBase documentation for additional information.

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud Bigtable Documentation