Using the Fyne toolkit to build cross platform applications is very simple but does require some tools to be installed before you can begin. If your computer is set up for development with Go then the following steps may not be required, but we advise reading the tips for your operating system just in case. If later steps in this tutorial fail then you should re-visit the prerequisites below.
Fyne requires 3 basic elements to be present, the Go tools (at least version 1.19), a C compiler (to connect with system graphics drivers) and a system graphics driver. The instructions vary depending on your operating system, choose the appropriate tab below for installation instructions.
Note that these steps are just required for development - your Fyne applications will not require any setup or dependency installation for end users!
You will need to add ~/Go/bin to your $PATH, for MSYS2 you can paste the following command into your terminal:
$ echo "export PATH=\$PATH:~/Go/bin" >> ~/.bashrc
For the compiler to work on other terminals you will need to set up the windows %PATH% variable to find these tools. Go to the “Edit the system environment variables” control panel, tap “Advanced” and add “C:\msys64\mingw64\bin” to the Path list.
Download Go from the download page and follow instructions.
Set up the Xcode command line tools by opening a Terminal window and typing the following:
xcode-select --install
In macOS the graphics drivers will already be installed.
You will need to install Go, GCC and the graphics library header files using your package manager. Choose the command corresponding to your distribution:
Debian, Ubuntu and Raspberry Pi OS:sudo apt-get install golang gcc libgl1-mesa-dev xorg-dev libxkbcommon-dev
You will need to install Go, GCC and the graphics library header files using the package manager. Choose the command corresponding to your BSD system:
FreeBSD:sudo pkg install go gcc xorg pkgconf
OpenBSD:sudo pkg_add go
NetBSD:sudo pkgin install go pkgconf
Compiling to Android from a desktop computer:
To develop apps for Android you will first need to install the tools for your current computer (Windows, macOS or Linux).
Once complete you will need to install the Android SDK and Android NDK - the recommended approach is to install Android Studio and then go to Tools > SDK Manager and from SDK Tools install the NDK (Side by side) package.
Alternatively you can download the Standalone Android NDK which is a more lean approach. Extract the folder and point the ANDROID_NDK_HOME environment variable to it.
Compiling on the Android device itself using Termux (video tutorial can be found here):
Install fdroid and then install termux from there.
Open Termux and install Go and Git:
pkg install golang git
Install NDK and SDK to termux from https://github.com/Lzhiyong/termux-ndk and set environment variables ANDROID_HOME and ANDROID_NDK_HOME appropriately.
To develop apps for iOS you will need access to an Apple Mac computer, configured according to the macOS tab above.
You will also need to create an Apple Developer account and sign up to the developer program (costs apply) to obtain the necessary certificate to run your app on any devices.
Since Go 1.16 you will need to set up the module before you can use the package.
Run the following command and replace MODULE_NAME with your preferred module name (this should be called in a new folder specific for your application).
$ mkdir myapp
$ cd myapp
$ go mod init MODULE_NAME
You now need to download the Fyne module and helper tool. This will be done using the following commands:
$ go get fyne.io/fyne/v2@latest
$ go install fyne.io/tools/cmd/fyne@latest
Before coding an app or running an example you can check your install using the
Fyne Setup tool.
Simply download the right app for your computer from the link and run it,
you should see something like the following screen:
If there are any problems with your installation see the troubleshooting section for hints.
If you want to see the Fyne toolkit in action before you start to code your own application,
you can see our demo app running on your computer by executing:
$ go run fyne.io/demo@latest
Please note that the first run has to compile some C-code and can thus take longer than usual. Subsequent builds reuse the cache and will be much faster.
If you want to, you can also install the demo using the following command (requires Go 1.16 or later):
$ go install fyne.io/demo@latest
If your GOBIN environment has been added to path (should be by default on macOS and Windows), you can then run the demo:
$ demo
And that’s all there is to it! Now you can write your own Fyne application in your IDE of choice. If you want to see some Fyne code in action then you can read your first application.