Install Apache Cassandra from command line on Windows

13 Jul, 2016

LinkedInTwitter

A bit of history

In the past, Windows users had to download and run .exe or installers manually from websites. Package management was something reserved to Linux ecosystem within tools such as Aptitude.

That is the past. Now (since 2011 to be more accurate) exists a really handy tool called Chocolatey.

Chocolatey is a package manager and installer for software packages, built for the Windows platform. It is an execution engine using the NuGet packaging infrastructure and Windows PowerShell to provide an automation tool for installing software on Windows machines, designed to simplify the process from the user’s perspective.The name is an extension on a pun of NuGet (from “nougat“) as there are nougats with chocolate ingredients.

PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. One of the cool features of PowerShell: It has a powerful object-based pipeline.

Even better, since Windows 10, Microsoft has embedded to PowerShell a package manager named OneGet.

Need to figure out captions…

“OneGet is a unified interface to package management systems and aims to make Software Discovery, Installation and Inventory (SDII) work via a common set of cmdlets (and eventually a set of APIs). Regardless of the installation technology underneath, users can use these common cmdlets to install/uninstall packages, add/remove/query package repositories, and query a system for the software installed. Included in this CTP is a prototype implementation of a Chocolatey-compatible package manager that can install existing Chocolatey packages.”

On the plus side, Chocolatey integrates as well with several infrastructure automation tools such as Ansible, Puppet, Chef, SCCM…

Nice! So what about Cassandra from command line?

Here you go:

If you are using Windows 10, just use OneGet from Powershell:

Install-Package apache-cassandra

Otherwise, if you still prefer to use Chocolatey or haven’t OneGet on your client, start by installing Chocolatey using:

From Cmd.exe:

@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%chocolateybin

From Powershell.exe (Ensure Get-ExecutionPolicy is at least RemoteSigned):

iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))

From PowerShell v3+ (Ensure Get-ExecutionPolicy is at least RemoteSigned):

iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex

Then all you need is to type in a shell:

choco install apache-cassandra

or

cinst apache-cassandra

It will install Apache Cassandra on your chocolatey tools folders “C:/tools”. See? Easy.

If you are interested in this package and would like to see others versions of C* available on OnGet, let us know by sending an email or contacting us throught this git repo: https://github.com/digitalis-io/chocolatey-packages

Blog Extra:

You like to use the watch command on Linux and would like to do the same on windows, just as this function to your PowerShell profile (usually located in “C:Users*yourUserName*DocumentsWindowsPowerShell”):

function watch([scriptblock]$Command_ = {Get-Process}, 
[int]$Seconds_ = 2){
	$private:sb = New-Object System.Text.StringBuilder
	$private:w0 = $private:h0 = 0
	for(;;) {
		# invoke command, format output data
		$private:n = $sb.Length = 0
		$private:w = $Host.UI.RawUI.BufferSize.Width
		$private:h = $Host.UI.RawUI.WindowSize.Height-1
		[void]$sb.EnsureCapacity($w*$h)
		.{
			& $Command_ | Out-String -Stream | .{process{
				if ($_ -and ++$n -le $h) {
					$_ = $_.Replace("`t", ' ')
					if ($_.Length -gt $w) {
						[void]$sb.Append($_.Substring(0, $w-1) + '*')
					}   
					else {
						[void]$sb.Append($_.PadRight($w))
					}
				}
			}}
		}>$null
		# fill screen
		if ($w0 -ne $w -or $h0 -ne $h) {
			$w0 = $w; $h0 = $h
			Clear-Host; $private:origin =
$Host.UI.RawUI.CursorPosition
    }
    else {
      $Host.UI.RawUI.CursorPosition = $origin
    }
    Write-Host $sb -NoNewLine
    $private:cursor = $Host.UI.RawUI.CursorPosition
    if ($n -lt $h) {
      Write-Host (' '*($w*($h-$n)+1)) -NoNewLine
    }

    elseif($n -gt $h) {
      Write-Host '*' -NoNewLine
    }
    $Host.UI.RawUI.CursorPosition = $cursor
    Start-Sleep $Seconds_
  }
}

Which will execute the cassandra nodetool status command every 2 seconds:

Happy OneGetting!

Categories

Archives

Related Articles