|
| 1 | +--- |
| 2 | +title: Installation |
| 3 | +description: Learn how to install Apify CLI, and how to create, run, and manage Actors through it. |
| 4 | +sidebar_label: Installation |
| 5 | +--- |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +You can install Apify CLI either using [Homebrew package manager](https://brew.sh) on macOS or Linux or using NPM on all platforms including Windows. |
| 10 | + |
| 11 | +### Via Homebrew |
| 12 | + |
| 13 | +Run the following command: |
| 14 | + |
| 15 | +```bash showLineNumbers |
| 16 | +brew install apify-cli |
| 17 | +``` |
| 18 | + |
| 19 | +### Via NPM |
| 20 | + |
| 21 | +First, make sure you have [Node.js](https://nodejs.org) version 18 or higher with NPM installed on your computer: |
| 22 | + |
| 23 | +```bash showLineNumbers |
| 24 | +node --version |
| 25 | +npm --version |
| 26 | +``` |
| 27 | + |
| 28 | +Install or upgrade Apify CLI by running: |
| 29 | + |
| 30 | +```bash showLineNumbers |
| 31 | +npm -g install apify-cli |
| 32 | +``` |
| 33 | + |
| 34 | +If you receive a permission error, read npm's [official guide](https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally) on installing packages globally. |
| 35 | + |
| 36 | +Alternatively, you can use [Node Version Manager (nvm)](https://github.com/nvm-sh/nvm) and install Apify CLI only into a selected user-level Node version without requiring root privileges: |
| 37 | + |
| 38 | +```bash showLineNumbers |
| 39 | +nvm install 18 |
| 40 | +nvm use 18 |
| 41 | +npm -g install apify-cli |
| 42 | +``` |
| 43 | + |
| 44 | +After using either of these methods , verify that Apify CLI was installed correctly by running: |
| 45 | + |
| 46 | +```bash showLineNumbers |
| 47 | +apify --version |
| 48 | +``` |
| 49 | + |
| 50 | +which should print something like: |
| 51 | + |
| 52 | +```bash showLineNumbers |
| 53 | +apify-cli/0.19.1 linux-x64 node-v18.17.0 |
| 54 | +``` |
| 55 | + |
| 56 | +## Basic Usage |
| 57 | + |
| 58 | +The following examples demonstrate the basic usage of Apify CLI. |
| 59 | + |
| 60 | +### Create a New Actor from Scratch |
| 61 | + |
| 62 | +```bash showLineNumbers |
| 63 | +apify create my-hello-world |
| 64 | +``` |
| 65 | + |
| 66 | +First, you will be prompted to select a template with the boilerplate for the Actor, to help you get started quickly. |
| 67 | +The command will create a directory called `my-hello-world` that contains a Node.js project |
| 68 | +for the Actor and a few configuration files. |
| 69 | + |
| 70 | +### Create a New Actor from Existing Project |
| 71 | + |
| 72 | +:::tip Automatic Actor directory initialization |
| 73 | +When you create an Actor using the `apify create` command, the directory will already be initialized. |
| 74 | +::: |
| 75 | + |
| 76 | +```bash showLineNumbers |
| 77 | +cd ./my/awesome/project |
| 78 | +apify init |
| 79 | +``` |
| 80 | + |
| 81 | +This command will only set up local Actor development environment in an existing directory, |
| 82 | +i.e. it will create the `.actor/actor.json` file and `apify_storage` directory. |
| 83 | + |
| 84 | +Before you can run your project locally using `apify run`, you have to set up the right start command in `package.json` under scripts.start. For example: |
| 85 | + |
| 86 | +```json showLineNumbers |
| 87 | +{ |
| 88 | + ... |
| 89 | + "scripts": { |
| 90 | + "start": "node your_main_file.js", |
| 91 | + }, |
| 92 | + ... |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +You can find more information about by running `apify help run`. |
| 97 | + |
| 98 | +### Run the Actor Locally |
| 99 | + |
| 100 | +```bash showLineNumbers |
| 101 | +cd my-hello-world |
| 102 | +apify run |
| 103 | +``` |
| 104 | + |
| 105 | +This command runs the Actor on your local machine. |
| 106 | +Now's your chance to develop the logic - or magic :smirk: |
| 107 | + |
| 108 | +### Login with your Apify account |
| 109 | + |
| 110 | +```bash showLineNumbers |
| 111 | +apify login |
| 112 | +``` |
| 113 | + |
| 114 | +Before you can interact with the Apify cloud, you need to [create an Apify account](https://console.apify.com/) |
| 115 | +and log in to it using the above command. You will be prompted for |
| 116 | +your [Apify API token](https://console.apify.com/settings/integrations). |
| 117 | + |
| 118 | +:::note API token save directory |
| 119 | +The command will store the API token and other sensitive information to `~/.apify`. |
| 120 | +::: |
| 121 | + |
| 122 | +### Push the Actor to the Apify Cloud |
| 123 | + |
| 124 | +```bash showLineNumbers |
| 125 | +apify push |
| 126 | +``` |
| 127 | + |
| 128 | +This command uploads your project to the Apify cloud and builds an Actor from it. On the platform, Actor needs to be built before it can be run. |
| 129 | + |
| 130 | +### Run an Actor on the Apify Cloud |
| 131 | + |
| 132 | +```bash showLineNumbers |
| 133 | +apify call |
| 134 | +``` |
| 135 | + |
| 136 | +Runs the Actor corresponding to the current directory on the Apify Platform. |
| 137 | + |
| 138 | +This command can also be used to run other Actors, for example: |
| 139 | + |
| 140 | +```bash showLineNumbers |
| 141 | +apify call apify/hello-world |
| 142 | +``` |
| 143 | + |
| 144 | +### So what's in this `.actor/actor.json` File? |
| 145 | + |
| 146 | +This file associates your local development project with an Actor on the Apify Platform. |
| 147 | +It contains information such as Actor name, version, build tag and environment variables. |
| 148 | +Make sure you commit this file to the Git repository. |
| 149 | + |
| 150 | +For example, `.actor/actor.json` file can look as follows: |
| 151 | + |
| 152 | +```json showLineNumbers |
| 153 | +{ |
| 154 | + "actorSpecification": 1, |
| 155 | + "name": "name-of-my-scraper", |
| 156 | + "version": "0.0", |
| 157 | + "buildTag": "latest", |
| 158 | + "environmentVariables": { |
| 159 | + "MYSQL_USER": "my_username", |
| 160 | + "MYSQL_PASSWORD": "@mySecretPassword" |
| 161 | + }, |
| 162 | + "dockerfile": "./Dockerfile", |
| 163 | + "readme": "./ACTOR.md", |
| 164 | + "input": "./input_schema.json", |
| 165 | + "storages": { |
| 166 | + "dataset": "./dataset_schema.json" |
| 167 | + } |
| 168 | +} |
| 169 | +``` |
| 170 | + |
| 171 | +**`Dockerfile` field** |
| 172 | + |
| 173 | +If you specify the path to your Docker file under the `dockerfile` field, this file will be used for Actor builds on the platform. If not specified, the system will look for Docker files at `.actor/Dockerfile` and `Dockerfile` in this order of preference. |
| 174 | + |
| 175 | +**`Readme` field** |
| 176 | + |
| 177 | +If you specify the path to your readme file under the `readme` field, the readme at this path will be used on the platform. If not specified, readme at `.actor/README.md` and `README.md` will be used in this order of preference. |
| 178 | + |
| 179 | +**`Input` field** |
| 180 | + |
| 181 | +You can embed your [input schema](https://docs.apify.com/actors/development/input-schema#specification-version-1) object directly in `actor.json` under `input` field. Alternatively, you can provide a path to a custom input schema. If not provided, the input schema at `.actor/INPUT_SCHEMA.json` and `INPUT_SCHEMA.json` is used in this order of preference. |
| 182 | + |
| 183 | +**`Storages.dataset` field** |
| 184 | + |
| 185 | +You can define the schema of the items in your dataset under the `storages.dataset` field. This can be either an embedded object or a path to a JSON schema file. You can read more about the schema of your Actor output [here](https://docs.apify.com/actors/development/output-schema#specification-version-1). |
| 186 | + |
| 187 | +:::note Migration from deprecated config "apify.json" |
| 188 | +Note that previously, Actor config was stored in the `apify.json` file that has been deprecated. You can find the (very slight) differences and migration info in [migration guidelines](https://github.com/apify/apify-cli/blob/master/MIGRATIONS.md). |
| 189 | +::: |
0 commit comments