1. Overview

BASIC is a 3rd generation programming language created in 1963 by John G. Kemeny and Thomas E. Kurtz to facilitate programming on the Dartmouth computer system. However, while BASIC gained widespread use in the 20th century, it’s rarely seen today and can be difficult to install and use within Linux.

In this tutorial, we’ll learn about the various dialects of BASIC and the difference between compiling and interpreting. Finally, we’ll cover the installation and use of two implementations of BASIC in Linux.

2. The BASIC Language

The BASIC programming language comes in different dialects that define various commands and behavior of the language. In this section, we’ll go over a few of the most popular, along with the difference between compiling and interpreting BASIC.

2.1. Dialects of BASIC

BASIC has a large number of dialects with differing behavior. Different sets of standards have been created for BASIC including Minimal BASIC and ANSI (Full) BASIC. However, BASIC implementations rarely follow these standards.

Nevertheless, some implementations are compatible with ANSI BASIC such as Decimal BASIC and BAS-2.5.

One of the more popular dialects of BASIC is Microsoft’s QuickBASIC. Although QuickBASIC itself can only be run on DOS, many different implementations of BASIC have similar compatibility and syntax to QuickBasic including, QB64, QBasic, and FreeBASIC.

Another dialect of BASIC worth mentioning is Liberty Basic. While, Liberty Basic was originally created for Windows and OS/2, the GNU-Liberty Basic Compiler Collection allows for cross-platform compilation for Windows and Linux.

2.2. Compiling vs. Interpreting

Compiling is the process of turning code into machine code before execution. On the other hand, interpreting parses the code while executing it, allowing code to be run immediately.

Compiling is generally preferable in situations where a large, complex project needs to be run, or for distributing an executable file. Interpreting is preferable during the development process for getting instant feedback or testing short snippets of code.

Since not all BASIC implementations include both a compiler and interpreter, it’s important to consider the requirements before deciding on an implementation to use.

3. FreeBASIC

FreeBASIC is an implementation of BASIC compatible with Quick BASIC. It comes with a compiler, but not an interpreter or editor. Additionally, FreeBASIC has an active forum located at https://www.freebasic.net/forum/.

3.1. Ubuntu Dependencies

Before we can install FreeBASIC, we first need to install its dependencies. In this example, we’re using Ubuntu, though the dependencies may vary on other distributions.

The dependencies are in the default Ubuntu repositories, so we’ll install them using apt-get:

$ sudo apt-get -y install gcc libncurses-dev libtinfo-dev libffi-dev libgl1-mesa-dev libx11-dev libxext-dev libxrender-dev libxrandr-dev libxpm-dev

We use apt-get install to install our space-separated list of packages, using the -y option to confirm prompts during installation.

3.2. Install FreeBASIC

After, installing the dependencies, we can download and install FreeBASIC. The latest version of FreeBASIC can be found at https://sourceforge.net/projects/fbc/files/. Let’s download and extract the binary:

$ url='https://sourceforge.net/projects/fbc/files/FreeBASIC-1.10.1/Binaries-Linux/FreeBASIC-1.10.1-ubuntu-22.04-x86_64.tar.gz/download'
$ curl -s -L "${url}" | tar -xz

In this example, we use curl to download the file, using -s to follow redirects and -L to resolve to the correct URL and pipe to the tar command to extract the output.

Now we should have a directory with the format FreeBASIC-{version}-{architecture}. Finally, we can install:

$ cd FreeBASIC-*
$ sudo ./install.sh -i
FreeBASIC compiler successfully installed in /usr/local

Next, we change directories into the download directory and then run the ./install script with -i to install. To uninstall FreeBASIC, we can run ./install -u.

3.3. Compiling

The command for FreeBASIC is fbc. Let’s first run it without any options and see what happens.

$ fbc
usage: fbc [options] <input files>
...

The output will be usage information about fbc. In addition, we can get more information by looking at the man page.

Next, let’s create a simple “Hello World” program in BASIC:

$ echo 'PRINT "Hello World!"' > hello_world.bas

We use echo to output PRINT “Hello World!”, and redirect the output into the file hello_world.bas.

The hello_world.bas file now contains our program and is ready for compilation:

$ fbc hello_world.bas

The fbc command will compile files passed to it with the .bas file extension. We can also compile files with different file extensions using the -b option.

The output of this command will be an executable file, in this case, hello_world. Let’s run this file and see the output:

$ ./hello_world
Hello World!

In this example, we run the executable and it outputs the result onto the terminal.

4. Decimal BASIC

Decimal BASIC is an implementation that supports the majority of the ANSI BASIC standard. It comes with an editor that can run code, with the ability to output graphics or text.

4.1. Installing

Decimal BASIC comes either with GTK2 or QT5 for its user interface. In this example, we’ll be installing the GTK2 version.

Let’s download Decimal BASIC:

$ url='https://decimalbasic.web.fc2.com/BASIC8126En_Linux64.tar.xz'
$ curl "${url}" | tar -xJ

After downloading, the resulting directory contains Decimal BASIC as the executable BASIC812EN/basic. We can execute this file directly to run Decimal BASIC.

However, to make things easier, let’s add it to /usr/local/bin:

$ chmod 755 BASIC812En/basic*
$ sudo cp --preserve=mode BASIC812En/basic* /usr/local/bin

In this example, we first use chmod to ensure the files we’re copying have the right permissions. Then we use cp to copy the basic executable and other required files into our /usr/local/bin/. We use the –perserve=mode option to ensure the files we copy keep their permissions. Now, we can run basic without specifying its full path.

4.2. Using Decimal BASIC

Let’s first begin by running basic without any commands:

$ basic

We should now see the Decimal BASIC editor open in a new window. To run our code we can press or the run button in the editor:

Decimal Basic Editor, running program with output

After running our program, we’ll see its output in a new window. Additionally, we can stop the program execution by pressing Break or .

We can also execute a file directly from the command line:

$ basic -NI hello_world.bas

This will execute our program and then exit immediately when finished. To keep the output window and editor open after execution we use the -OR option.

5. Conclusion

In this article, we learned about a few different dialects of BASIC and about the difference between interpreting and compiling.

Next, we covered the installation and use of FreeBASIC and then Decimal BASIC.