Make sure you have an up-to-date version of Node.js installed on your system. If you don't have Node.js installed, you can install it from here.
Open a terminal window (Mac) or a command window (Windows), and install Cordova and Ionic:
npm install -g cordova ionic
On a Mac, you may have to use sudo depending on your system configuration:
sudo npm install -g cordova ionic
If you already have Cordova and Ionic installed on your computer, make sure you update to the latest version:
npm update -g cordova ionic
sudo npm update -g cordova ionic