With the open-source NativeScript command-line interface and an IDE or text editor of your choice, you can create, develop, store, and build your apps locally, free of charge and anonymously. Let’s look at how to set up the CLI for development.
TIP: Try NativeScript Sidekick for a one-click setup experience for macOS, Windows, and Linux. Sidekick installs the NativeScript CLI and dependencies listed below for macOS and Windows - and offers starter kits, cloud-based builds for iOS and Android, and app store publishing.
The NativeScript CLI is built on Node.js, and as such you need to have Node.js installed to use NativeScript.
To check whether you have Node.js installed, open a terminal or command prompt and execute
node --version. If there is an error, head to https://nodejs.org/ and download and install the latest “LTS” (long-term support) distribution and restart your terminal or command prompt.
- If you’re on macOS and use Homebrew, you can alternatively install the Node.js LTS release by running
brew update(to download the latest updates) and then
brew install node@8in your terminal.
- The NativeScript CLI supports a wide variety of Node.js versions, so if you already have Node.js installed you should be good to go. If, by chance, you’re running an unsupported version, the
tns doctorcommand will run momentarily and flag the problem so you can upgrade.
NOTE: Mac users, bear in mind that you should add the path to
node@8/binmanually by running
echo 'export PATH="/usr/local/opt/node@8/bin:$PATH"' >> ~/.bash_profileand restart your terminal.
Open your terminal or command prompt and execute the following command to install the NativeScript CLI from npm, which is the Node.js package manager:
npm install -g nativescript
- You may be asked two questions during the installation—Do you want to visit the official documentation?, and Do you want to run the setup script? Go ahead and answer “No” to both questions for now as we’ll cover the documentation and scripts momentarily.
- If you’re on macOS and receive an EACCES error, you either need to rerun the previous command with
sudo npm install -g nativescript—or take a moment to fix your npm permissions so that you don’t need admin rights to globally install npm packages.
After completing the setup there should be two commands available on the terminal/command prompt:
tns (short for Telerik NativeScript) and
nativescript. The two commands are identical, so we'll stick with the shorter
Verify that the installation was successful by running
tns in the terminal. You should see a long list of commands that starts with this section:
$ tns # NativeScript ┌─────────┬─────────────────────────────────────────────────────────────────────┐ │ Usage │ Synopsis │ │ General │ $ tns <Command> [Command Parameters] [--command <Options>] │ │ Alias │ $ nativescript <Command> [Command Parameters] [--command <Options>] │ └─────────┴─────────────────────────────────────────────────────────────────────┘
NativeScript builds truly native iOS and Android apps, and as such, each target platform needs setting up on the development machine. To ease the pain of installing all of these requirements manually, the
tns command provides quick-start scripts for Windows and macOS. Let’s look at how they work.
- Setting up your machine for native development can be tricky, especially if you’re new to mobile development. If you get stuck, or if you have questions while going through these instructions, Stack Overflow is a great place to get help.
- If you’re not comfortable with a script automatically installing dependencies on your development machine, or if you’re on Linux, refer to one of the advanced setup guides below for details on manually installing the iOS and Android dependencies.
- Also look at NativeScript Sidekick for cloud builds (includes free tier)
- Windows 7 Service Pack 1 or later
If running OS is Windows; copy and paste the script below into your command prompt as an administrator and press Enter:
Please be sure that you run this command in cmd as an administator (Windows key > type "cmd" > right click > Run as Administrator).
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://www.nativescript.org/setup/win'))"
During installation you may need to accept a User Account Control prompt to grant the script administrative privileges. Also, be aware that the script downloads and installs some big dependencies—so it’s common for the script to take a while to complete. When the script finishes, close and reopen your command prompt.
NOTE: On Windows and Linux systems you can only use the
tnscommand to develop Android apps. This is because the NativeScript CLI uses Xcode to build iOS apps, which is only available on macOS. If you’re interested in building iOS apps on Windows or Linux, you should download NativeScript Sidekick.
After the installation the system setup should have:
- The latest stable official release of Node.js (LTS) 8.x
- Google Chrome
- JDK 8
- Android SDK 22 or a later stable official release
- Android Support Repository
- Google Repository
- Android SDK Build-tools 27.0.3 or a later stable official release
- Android Studio
- Set up Android virtual devices to expand your testing options
The two environment variables
ANDROID_HOME are required for Android development, which should have been automatically added as part of the installation:
NOTE To check if
- close any open Command Prompt windows,
- open a new Command Prompt
echo %JAVA_HOME%and make sure a valid path is returned
echo %ANDROID_HOME%and make sure a valid path is returned
Tip You can install and use custom Android Virtual Devices that are emulating different API levels and screens.
If OS is a Mac, copy and paste the script below into your terminal and press Enter:
ruby -e "$(curl -fsSL https://www.nativescript.org/setup/mac)"
The macOS script needs administrative access to run some commands using
sudo; therefore, you may need to provide your password several times during execution. The macOS script also may take some time to complete, as it’s installing the dependencies for both iOS and Android development. When the script finishes, close and restart your terminal.
To verify the setup, run the
tns doctor command which will check for any issues with the installation. If you see “No issues were detected” you’re good to go!