| title | Setting up Linux for NativeScript | ||
|---|---|---|---|
| prev | /setup | ||
| next | /guide/creating-a-project | ||
| contributors |
|
You will need Node, NativeScript CLI (command line interface), Android Studio and a JDK (java development kit).
Android Studio is not strictly necessary — however it provides an easy-to-use interface for installing and managing the Android SDKs.
To install Node follow the instructions specific to your Linux distribution. We recommend using the latest version, however anything above Node 14 should be fine.
:::warning Note We have gone through these steps on Ubuntu 20.04 and noted the commands we used, however depending on your Linux distribution, the commands may be different. We cannot provide commands for all possible distributions, so please refer to the linked documentation to find the correct commands you need to run. :::
# On Ubuntu 20.04, we used the following command to install latest node
$ curl -fsSL https://deb.nodesource.com/setup_15.x | sudo -E bash -
$ sudo apt-get install -y nodejsTo confirm Node is installed correctly, run:
$ node -v
$ npm -v
# Should print something like
$:v22.x.x
10.x.xA JDK version 8 or greater is required, and you have a couple options:
- OpenJDK - Adoptium — can be downloaded from Adoptium or your system package manager.
- OpenJDK - AdoptOpenJDK — can be downloaded from AdoptOpenJDK or your system package manager.
- Oracle JDK — can be downloaded directly or through the system package manager.
# On Ubuntu 20.04, we used the following command to install OpenJDK 17
sudo apt-get install -y openjdk-17-jdkTo confirm JDK is installed correctly, run:
$ java --version
$ javac --version
# Should print something like
$:openjdk 17.x.x 202x-xx-xx
OpenJDK Runtime Environment (build xx.x.x+xx-Ubuntu-xxx.xx)
OpenJDK 64-Bit Server VM (build xx.x.x+xx-Ubuntu-xxx.xx, mixed mode, sharing)
javac 17.x.x:::tip Note NativeScript uses Gradle for Android builds. Different versions of Gradle rely on certain versions of Java to work. If a build fails, check whether the version of Java installed on your system is compatible with the version of Gradle used by NativeScript. The version of Gradle used by NativeScript can be seen in the build logs or in the source. :::
Setting up the Android development environment can be daunting if you are new to Android development, however following the next steps carefully will get you up and running in no time.
Download and install Android Studio. In the installation wizard, make sure you have the following components selected (the list should appear if you select custom options):
- Android SDK
- Android SDK Platform
- Android Virtual Device
The setup may take a while, but once it has finished a welcome screen should appear.
Android Studio installs the latest Android SDK by default, which in most cases should be all that's needed to build a NativeScript app.
Configure the ANDROID_HOME environment variable for NativeScript to be able to find the Android SDK, and add the required tools to path.
Add the following lines to your shell profile, usually ~/.bash_profile or ~/.bashrc, or if you are using zsh then ~/.zshrc config file:
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/platform-toolsInstall the NativeScript CLI globally:
npm install -g nativescript:::tip Note
Depending on how you installed Node, you may get an EACCESS: permission denied error when trying to install a global package. It's generally not recommended to run npm with sudo, see this guide for Resolving EACCESS permissions errors.
:::
To verify that the installation was successful, open a new Command Prompt window (to ensure the new environment variables are loaded) and run
ns doctor androidIf you see No issues were detected then you have successfully set up your system.
::: warning Experimental The Linux platform is experimental. APIs, tooling and requirements may change between releases. See Developing for Linux for the current status. :::
NativeScript can build native Linux desktop apps with GTK 4. Apps run on the local machine.
You will need:
- A glibc based Linux distribution released in 2018 or later (glibc 2.28 or newer), x64 or arm64
- GTK 4
- Node — see Setting up Linux for Android above
- The NativeScript CLI
Most desktop distributions already ship GTK 4. If yours doesn't, install it with your package manager:
::: code-group
sudo apt install libgtk-4-1sudo dnf install gtk4sudo pacman -S gtk4:::
Apps and plugins that include their own C or C++ code (see Adding Linux native code) also need a C compiler, pkg-config and, for CMake projects, cmake, as well as the development packages of the libraries they use:
::: code-group
sudo apt install build-essential pkg-config cmake libgtk-4-devsudo dnf install gcc gcc-c++ pkgconf-pkg-config cmake gtk4-develsudo pacman -S base-devel cmake gtk4:::
Apps that only use JavaScript/TypeScript don't need these.
If you haven't already, install the NativeScript CLI globally:
npm install -g nativescriptRun:
ns doctorOn Linux the output includes a Linux section, which checks that the GTK 4 library (libgtk-4.so.1) is installed. If it reports no issues, your environment is ready.
Your machine is also listed as a Linux device:
ns devices linuxYou're now ready to add the Linux platform to a project.
:::danger ❌ Unsupported
A Mac is required to build projects that use native iOS code. Simpler apps can be tested using NativeScript Preview.
:::