Installing Ionic
Like Ionic 1, Ionic 2 apps can be quickly created from the Ionic CLI or GUI tool or built and tested right in the browser.
To install the Ionic SDK and create Ionic 2 projects, you’ll need to install the latest beta release:
$ npm install -g ionic@beta
Make sure you have NodeJS installed. Download the installer here. It’s best to get the 4x version of node for stability. Unfamiliar with NPM? Learn more about it and what packages we use here
Worried about your V1 Ionic projects? Don’t worry! The beta release has all the functionality to work with both V1 projects and V2 projects.
Once that’s done, create your first Ionic app:
$ ionic start cutePuppyPics --v2
To run your app, cd
into the directory that was created and then run the ionic serve
command:
$ cd cutePuppyPics
$ ionic serve
You can play with it right in the browser!
Building to a Device
After you have Ionic installed, you can build your app to a physical device. If you don’t have a physical device on hand, you can still build to a device emulator. Check out the iOS simulator docs if you are on a Mac, or the Genymotion docs if you are looking to emulate an Android device. You will also need Cordova to run your app on a native device. To install Cordova, run:
$ sudo npm install -g cordova
Once you have Cordova installed and a device or emulator ready to go, you can move on and begin building your app!
Building for iOS
To build for iOS, we need to add the iOS platform module to Cordova:
Next, you’ll need to install Xcode. Xcode allows you to build compile to a target device running iOS.
From there, you should be able to run the iOS emulator using the following command:
$ ionic emulate ios
Building for Android
To build for Android, you’ll need to add the Android platform module to Cordova:
$ ionic platform add android
Next, you’ll need to install the Android SDK. The Android SDK allows you to build compile to a target device running Android. Although the Android SDK comes with a stock emulator, Genymotion is recommended, since it’s much faster. Once installed, start an Android image and run:
$ ionic run android