How to install bin2src on Ubuntu using Snap

Snap is a popular package manager that allows you to easily install software on Linux-based Operating Systems. It was developed and is maintained by Canonical. Snap was originally created for cloud-based applications, but its support has since been extended to include desktop applications and IoT devices. The packages installed using snap are referred to as snaps and the service that maintains the snaps is known as snapd.

In this article, we will briefly demonstrate how to install bin2src – Convert bytes to source code on Ubuntu using snap.

What is bin2src


bin2src takes an input stream of bytes and converts
that into source code. That source code version of the
input can then be easily embedded into your project with Copy+Paste.


Read bytes from STDIN and write them to STDOUT:

$ echo "hello" | bin2src

Note that there is no need to convert your input bytes to a plain text encoding:

$ head -c 10 /dev/urandom | bin2src 

The primary purpose of bin2src is to facilitate embedding binary blobs into software source code.

To specify an output format, use the -f option (“f” for format):

$ head -c 10 /dev/urandom | bin2src -f python
DATA = """\x22\x82\x2d\xd4\xb8\x8c\x36\xb4\x35\x21"""

If you would like to change the variable name, use the -a option (“a” is a common mathematical variable):

$ head -c 10 /dev/urandom | bin2src -f python -a RAND_BYTES
RAND_BYTES = """\xf5\xde\x5e\xdc\x66\xeb\x89\x24\x13\xd5"""

Other options are available. See the full list by running bin2src --help.

Supported output formats

  • plaintext (default)
  • go
  • rust
  • python

How to install snapd on Ubuntu

snapd is the service that runs and manages snaps for you, including performing automatic updates. Installation instructions and supported versioning information for each of the following Linux distributions can be found here.

See also  How to install bosh-cli on Ubuntu using Snap

If you’re running Ubuntu 16.04 LTS (Xenial Xerus) or later, including Ubuntu 18.04 LTS (Bionic Beaver), Ubuntu 18.10 (Cosmic Cuttlefish) and Ubuntu 19.10 (Eoan Ermine), you don’t need to do anything. Snap is already installed and ready to go.

For versions of Ubuntu between 14.04 LTS (Trusty Tahr) and 15.10 (Wily Werewolf), as well as Ubuntu flavours that don’t include snap by default, snap can be installed from the Ubuntu Software Centre by searching for snapd.

Alternatively, snapd can be installed from the command line:

sudo apt update
sudo apt install snapd

Once the command completed itself, update your system paths for snap by logging out and back in again, or restarting your computer.

For those who need to know which version of Ubuntu you’re running, open System Settings and select Details. Alternatively, from the command line, type lsb_release -a.

Verify that snapd is running

Before actually installing bin2src, check the status of the “snapd” service by running the following command:

sudo systemctl status snapd.socket


In our case, it shows that the snapd service is already installed and running without any issues.

Install bin2src snap – Convert bytes to source code

Login to the Ubuntu system and then open the terminal by pressing CTRL+ALT+ T buttons. Run below command to install the bin2src snap package. The bin2src snap package is published by Tim McNamara and has been verified by the Snap team as safe. At the time of this writing, the current version of bin2src is 0.1.1.

sudo snap install --classic 

The --classic argument is required here as bin2src needs full access to your system in order to be useful, therefore it needs snap’s “classic confinement”. By default, snaps are much more restricted in their ability to access your disk and network, and they have to request special access from you where they need it.

See also  How to install https-forward on Ubuntu using Snap

Please note that bin2src package installed with snap is auto-updated, which means you don’t have to do anything to be able to use the latest version of bin2src, unlike with apt or yum.


You can find more details about bin2src at its official website. Snaps are much more than just a new Linux package format – they’re a sophisticated way to deliver complex applications to any desktop environment! To get started with snaps, learn about their security features, transactions and more from the man page or Canonical’s advanced snap usage tutorial. There are also plenty of great snaps besides bin2src – Convert bytes to source code available in the store for your Linux desktop, like vscode, atom, slack and spotify.

Author: Kub Cornell  A tech enthusiast, driven by curiosity. A bibliophile who loves to travel. An Engineering graduate who loves to code and write about new technologies. Can’t sustain without coffee.

Leave a Comment