Journal for Developers

How to Set Up NativeScript on Development Machine

NativeScript Logo
0 68

Notice: Undefined index: rate in /home/content/p3pnexwpnas11_data03/84/3795084/html/wp-content/themes/publisher/includes/functions.php on line 5360
4 min read

In continuation to the previous article “Getting Started with NativeScript”, here we are with the next step, that is, setting up your development environment before you start the work of development with NativeScript.

Setting Up your Development Machine

All you need is an IDE of your choice and the open-source NativeScript CLI (command line interface). With the help of these two things, you can create, develop, store and build your apps entirely locally.

NOTE: If you are Windows user then you might be interested in trying the Windows Installer instead of following the manual steps specified below.

Step #1: Install Node.js

You need to have Node.js installed to use NativeScript because the NativeScript CLI is built on Node.js.

To check whether you already have Node.js installed, open a terminal or command prompt on your development machine and execute the following command node --version. If you get an error, head to https://nodejs.org/ and download and install the latest “LTS” (long-term support) distribution for your development machine.

! TIP:

  • 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 available updates and then brew install node@6 in 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 doctor command we’ll run momentarily will flag the problem so you can upgrade.
  • NOTE: Bear in mind that you should add the path to node@6/bin manually by running echo 'export PATH="/usr/local/opt/node@6/bin:$PATH"' >> ~/.bash_profile in your terminal.

Step #2: Install the NativeScript CLI

On your terminal or command prompt, execute the following command to install the NativeScript CLI from npm (node.js package manager).

npm install -g nativescript

After completing the setup, there are two commands available to use NativeScript from terminal or command prompt: tns—which is short for Telerik NativeScript—and nativescript. The two commands are synonymous, so let’s stick with the shorter tns.

Let’s verify whether the installation was successful or not by running tns in your terminal. You should see something like this:

TNS Command

Step #3: Install iOS and Android Requirements

When you build with NativeScript you’re building truly native iOS and Android apps, and for this magic to happen, you need to set up each platform you intend to build for on your development machine. The NativeScript CLI provides quick-start scripts for Windows and macOS to ease the pain of installing all of these requirements manually by handling the necessary setup for you automatically. Now let’s have a look at how they work.

Windows:

If you’re on Windows, copy and paste the script below into your command prompt and press Enter:

@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 systems you can only use the NativeScript CLI to develop Android apps. This is because the NativeScript CLI uses Xcode to build iOS apps, which is only available on the macOS operating system. If you’re interested in building iOS apps on Windows, you may want to try out the Telerik Platform. The Telerik Platform provides robust tooling for NativeScript apps, including a service that performs iOS and Android builds in the cloud, removing the need to complete these system requirements, and allowing you to build for iOS on Windows.

macOS

If you’re a Mac user, copy and paste the script below into your terminal and press Enter:

ruby -e “$(curl -fsSL https://www.nativescript.org/setup/mac)”

Much like the Windows script, 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.

Step #4: Verify

Once you are finished with the installation of NativeScript and its dependencies, run the tns doctor command, which will check for any issues with your installation.

If you see “No issues were detected” then you’re all setup to start using NativeScript.

Next steps will be starting phase of actually learning the NativeScript basics.

Subscribe to our Journal

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!