Wednesday, 26 December 2018

How to install Gimp on Ubuntu 18.06

$ sudo add-apt-repository ppa:otto-kesselgulasch/gimp
$ sudo apt-get update
$ sudo apt-get install gimp

How to install Go on Nvidia Jetson TX2

Downloads page on Go's website lists archives and installers for all major operating systems and architectures. Jetson TX runs custom version of Ubuntu called Linux for Tegra (L4T):

$ uname -a
Linux tegra-ubuntu 4.4.38-tegra #1 SMP PREEMPT Thu May 17 00:15:19 PDT 2018 aarch64 aarch64 aarch64 GNU/Linux




To find the processor architecture we can check out the content of /proc/cpuinfo file:

$ cat /proc/cpuinfo

processor : 0
model name : ARMv8 Processor rev 3 (v8l)
BogoMIPS : 62.50
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x1
CPU part : 0xd07
CPU revision : 3

processor : 3
model name : ARMv8 Processor rev 3 (v8l)
BogoMIPS : 62.50
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x1
CPU part : 0xd07
CPU revision : 3

processor : 4
model name : ARMv8 Processor rev 3 (v8l)
BogoMIPS : 62.50
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x1
CPU part : 0xd07
CPU revision : 3

processor : 5
model name : ARMv8 Processor rev 3 (v8l)
BogoMIPS : 62.50
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x1
CPU part : 0xd07
CPU revision : 3


We can see that Jetson TX2 uses version 8 of the ARM instruction set. Luckily, Go Downloads page provides archive for ARMv8 (Downloads >> Stable Versions >> Other Ports). At the time of writing the latest version was:

go1.11.4.linux-arm64.tar.gz Archive Linux ARMv8 96MB


Upon downloading the archive and verifying its checksum we can install Go by extracting it into /usr/local directory:

tar -C /usr/local -xzf go1.11.4.linux-arm64.tar.gz


Go binaries are in /usr/local/go/bin directory and to make them available from any new terminal session we have to add and persist this path to PATH environment variable.

We have to edit bash configuration:

$ sudo gedit ~/.bashrc

...by appending go bin path to PATH:

export PATH=(...):/usr/local/go/bin


Go installation requires defining which local directory will be Go workspace (place with all Go repositories - source code, builds and packages). I chose it to be dev/go directory in my home directory instead of the default one which is $HOME/go. For I am using non-default workspace location I have to add another environment variable in the same bash config file:

export GOPATH=$HOME/dev/go


As I've already created Go test project on my GitHub account when I was testing Go installation on Windows we can simply clone that project. Before we do it, let's make go get use SSH URL instead of HTTPS so we don't have to change it later manually (like on Windows). To achieve this we have to change global git configuration (suggested here):

$ git config --global url.git@github.com:.insteadOf https://github.com/


Let's do the clone now:

~/dev/go$ mkdir src
~/dev/go$ cd src
~/dev/go/src$ go get github.com/BojanKomazec/go-hello-world




We now have a sample go file: ~/dev/go/src/github.com/BojanKomazec/go-hello-world/hello/hello.go.

To verify that SSH URL has been used we can execute:

~/dev/go/src/github.com/BojanKomazec/go-hello-world$ git remote get-url origin
git@github.com:BojanKomazec/go-hello-world


Let's go to hello directory and build our go file:

$ go build hello.go


This creates hello executable that we can run:

$ ./hello
hello, world


This proves that our Go installation on Jetson TX2 was successful.

Saturday, 22 December 2018

Setting up Go on Windows

Go (Golang) is installed on Windows via its msi installer available on Go's website. The latest version at the time of writing this article was 1.11.4 and the installer go1.11.4.windows-amd64.msi.



Installation is straightforward:







By default, installer creates or modifies the following environment variables:

In System space:

   Variable (created): GOROOT
   Value: C:\Go\
   Description: Go installation location.

   Variable (value appended): Path
   Value: C:\Go\bin
   Description: Go binaries location.


In User space:

   Variable (created): GOPATH
   Value: %USERPROFILE%\go
   Description: User's go workspace path.

   Variable (value appended): Path
   Value: %USERPROFILE%\go\bin
   Description: User's Go applications' binaries location.


Go workspace:
  • a directory with two subdirectories: bin and src
    • src typically contains all repositories with Go projects
    • bin contains built and then installed Go application binaries
  • can be set at arbitrary location; I set mine to C:\dev\go (and also set User space Path to C:\dev\go\bin)

Upon installation, C:\Go\bin contains three binaries:
  • go -  Tool for managing Go source code
  • godoc - Documentation tool; parses Go source code - including comments - and produces documentation as HTML or plain text
  • gofmt - Go source code formatter; uses tabs for indentation and blanks for alignment. 



Let's see what are the command line arguments of go tool:

>go
Go is a tool for managing Go source code.

Usage:

        go <command> [arguments]

The commands are:

        bug         start a bug report
        build       compile packages and dependencies
        clean       remove object files and cached files
        doc         show documentation for package or symbol
        env         print Go environment information
        fix         update packages to use new APIs
        fmt         gofmt (reformat) package sources
        generate    generate Go files by processing source
        get         download and install packages and dependencies
        install     compile and install packages and dependencies
        list        list packages or modules
        mod         module maintenance
        run         compile and run Go program
        test        test packages
        tool        run specified go tool
        version     print Go version
        vet         report likely mistakes in packages

Use "go help <command>" for more information about a command.

Additional help topics:

        buildmode   build modes
        c           calling between Go and C
        cache       build and test caching
        environment environment variables
        filetype    file types
        go.mod      the go.mod file
        gopath      GOPATH environment variable
        gopath-get  legacy GOPATH go get
        goproxy     module proxy protocol
        importpath  import path syntax
        modules     modules, module versions, and more
        module-get  module-aware go get
        packages    package lists and patterns
        testflag    testing flags
        testfunc    testing functions





If we already have some Go project in some Git repository (like GitHub), we can use get command to clone the given repository:

C:\dev\go\src>go get github.com/BojanKomazec/go-hello-world
package github.com/BojanKomazec/go-hello-world: no Go files in
C:\dev\go\src\github.com\BojanKomazec\go-hello-world

Repository is cloned to C:\dev\go\src\github.com\BojanKomazec\go-hello-world directory.

Repository shall be written without starting https:// as go get would report an error:

C:\dev\go\src>go get https://github.com/BojanKomazec/go-hello-world
package https:/github.com/BojanKomazec/go-hello-world: https:/github.com/BojanKomazec/go-hello-world: invalid import path: malformed import path "https:/github.com/BojanKomazec/go-hello-world": invalid char ':'

This my repository only has .gitignore and README.md files so let's add some code. First, let's create a directory named hello and in it a go file with the following content:

C:\dev\go\src\github.com\BojanKomazec\go-hello-world\hello\hello.go:

package main

import "fmt"

func main() {
   fmt.Printf("hello, world\n")
}


Building this file with:

C:\dev\go\src\github.com\BojanKomazec\go-hello-world\hello>go build

...creates a hello.exe file in the same directory and we can run it:

C:\dev\go\src\github.com\BojanKomazec\go-hello-world\hello>hello
hello, world

To install that build as a package, we have to run:

C:\dev\go\src\github.com\BojanKomazec\go-hello-world\hello>go install

This deploys application binary in C:\dev\go\bin directory.

go tool and Git

If we add, commit and then try to push hello.go file to remote repository, we'll be prompted by Git to enter our GitHub credentials as by default go get sets the https-based URL of the remote. We can verify that with:

C:\dev\go\src\github.com\BojanKomazec\go-hello-world>git remote show origin
* remote origin
  Fetch URL: https://github.com/BojanKomazec/go-hello-world
  Push  URL: https://github.com/BojanKomazec/go-hello-world
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

We can set SSH-based URL by executing:

>git remote set-url origin git@github.com:BojanKomazec/go-hello-world.git

Let's verify it:

C:\dev\go\src\github.com\BojanKomazec\go-hello-world>git remote show origin
Enter passphrase for key '/c/Users/komazec/.ssh/id_rsa':
* remote origin
  Fetch URL: git@github.com:BojanKomazec/go-hello-world.git
  Push  URL: git@github.com:BojanKomazec/go-hello-world.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

Let's now analyse code in the go source file above.

package main

func main() {
   ...
}


This line tells the Go compiler that the package should compile as an executable program. Its entry point will be function main(). If we were building a shared library, we would use package lib directive and there would not be main() function in the package.

import "fmt"
...
fmt.Printf("hello, world\n")

import statement imports a package into other package. Here, we wanted to use function which prints a string onto standard output. Such function, Printf, is available in the fmt package which comes from the Go standard library. Go compiler looks for standard library packages on paths specified in GOROOT and your and third-party packages on path specified in GOPATH environment variables.

Project on GutHub:

https://github.com/BojanKomazec/go-hello-world

References:

golang.org: Go installation on Windows
Understanding Golang Packages
Package “main” and func “main”

Tuesday, 11 December 2018

Introduction to Yarn

Yarn
  • package manager
  • developed by Facebook
  • uses the same package.json as npm
  • uses its own lock file - yarn.lock (not package-lock.json like npm)
  • if installing it on Windows via installer, Node.js has to be installed first
  • once installed re-launch terminal and type yarn -v to verify that it's installed successfully and see its version
  • if you check out some project which uses yarn, you would typically first run yarn install to install all the dependencies of project
  • each module has npm-based and yarn-based packages so can be installed via either dependency manager. E.g. babel-core:
    • npm: npm install --save-dev @babel/core
    • yarn: yarn add @babel/core --dev

Sunday, 9 December 2018

How to install JetPack 3.3 on Ubuntu 18.04 and flash Jetson TX2

In July this year NVIDIA released JetPack 3.3 - currently the latest stable/production version of JetPack. Some of its features are:
This is the last JetPack that will be supporting Jetson TX2 and TX1 Developer Kits. JetPack 4.1.1 Developer Preview supports only new Jetson AGX Xavier Developer Kit but it will not be supporting TX2 or TX1).


Although official release notes for JetPack 3.3 state that supported Ubuntu on the host is 16.04, I had no issues installing this version of JetPack (and later flashing TX2) on my Ubuntu 18.04 with details:

~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic

I downloaded JetPack-L4T-3.3-linux-x64_b39.run from NVIDIA Developer Center, added execution permission and ran it as non-admin (installer prompts user for elevated privilege only when necessary). If you run it as super user, installer will show you an error: 


Installer unpacks its content into a directory whcih has the following content: 

~/Downloads/JetPack$ ls
64_TX2
devtools_docs
_installer
jetpack_docs
jetpack_download
JetPack-L4T-3.3-linux-x64_b39.run
JetPack_Uninstaller
NVIDIA_System_Profiler
nvl4t_docs
README.txt
Start_L4T_Docs.html
Tegra_Linux_Driver_Package_Release_Notes_R28.2.1.pdf

Although I got the following message as was running the installer on Ubuntu 18.04, I clicked "Yes" and had no issues during the process:


These are the screenshots of the successful JetPack 3.3 installation on Ubuntu 18.04 and flashing Jetson TX2:





It takes couple of seconds for Component Manager to download repo information, do version checks and show the current state of packages:












At this point I actually stopped the installation as wanted to do flashing of TX a bit later. This is possible as Component Manager will pick up and show the current state of all packages upon JetPack installer re-launch:











Now I pressed ENTER to resume the installation.








Just like before, I verified that all has completed successfully on TX2 by running some of installed CUDA demo examples (e.g. rendering ocean surface - "OceanFFT").