--- title: "Quickstart for dbt from a manual install" id: manual-install description: "Connecting your warehouse to dbt using the CLI." level: 'Beginner' platform: 'dbt' icon: 'square-terminal' tags: ['Quickstart'] hide_table_of_contents: true ---
## Introduction When you use from a manual install, you will be editing files locally using a code editor, and running projects using a command line interface (CLI). If you want to edit files and run projects using the web-based dbt Integrated Development Environment (), refer to the [ quickstarts](/guides). You can also develop and run dbt commands using the [ CLI](/docs/platform/dbt-cli-installation) — a powered command line. ### Prerequisites * To use , it's important that you know some basics of the Terminal. In particular, you should understand `cd`, `ls` and `pwd` to navigate through the directory structure of your computer easily. * Install using the [installation instructions](/docs/local/install-dbt) for your operating system. * Complete appropriate Setting up and Loading data steps in the Quickstart for series. For example, for BigQuery, complete [Setting up (in BigQuery)](/guides/bigquery?step=2) and [Loading data (BigQuery)](/guides/bigquery?step=3). * [Create a GitHub account](https://github.com/join) if you don't already have one. ### Create a starter project After setting up BigQuery to work with dbt, you are ready to create a starter project with example models, before building your own models. ## Create a repository The following steps use [GitHub](https://github.com/) as the provider for this guide, but you can use any provider. You should have already [created a GitHub account](https://github.com/join). 1. [Create a new GitHub repository](https://github.com/new) named `dbt-tutorial`. 2. Select one of the following (You can always change this setting later): - **Private (recommended):** To secure your environment and prevent private information (like credentials) from being public. - **Public:** If you need to easily collaborate and share with others, especially outside of your organization. 3. Leave the default values for all other settings. 4. Click **Create repository**. 5. Save the commands from "…or create a new repository on the command line" to use later in [Commit your changes](/guides/manual-install?step=6). ## Create a project Learn how to use a series of commands using the command line of the Terminal to create your project. includes an `init` command that helps scaffold a dbt project. To create your dbt project: 1. Make sure you have installed and check the version using the `dbt --version` command: ```shell dbt --version ``` 2. Initiate the `jaffle_shop` project using the `init` command: ```shell dbt init jaffle_shop ``` 3. Navigate into your project's directory: ```shell cd jaffle_shop ``` 4. Use `pwd` to confirm that you are in the right spot: ```shell $ pwd > Users/BBaggins/dbt-tutorial/jaffle_shop ``` 5. Use a code editor like VS Code to open the project directory you created in the previous steps, which we named jaffle_shop. The content includes folders and `.sql` and `.yml` files generated by the `init` command.
6. dbt provides the following values in the `dbt_project.yml` file: ```yaml name: jaffle_shop # Change from the default, `my_new_project` ... profile: jaffle_shop # Change from the default profile name, `default` ... models: jaffle_shop: # Change from `my_new_project` to match the previous value for `name:` ... ``` ## Connect to BigQuery When developing locally, dbt connects to your using a [profile](/docs/local/profiles.yml), which is a YAML file with all the connection details to your warehouse. 1. Create a file in the `~/.dbt/` directory named `profiles.yml`. 2. Move your BigQuery keyfile into this directory. 3. Copy the following and paste into the new profiles.yml file. Make sure you update the values where noted. ```yaml jaffle_shop: # this needs to match the profile in your dbt_project.yml file target: dev outputs: dev: type: bigquery method: service-account keyfile: /Users/BBAGGINS/.dbt/KEYFILE_NAME.json # Replace with the full path to your keyfile database: GCP_PROJECT_ID # Your Google Cloud project ID schema: dbt_YOUR_NAME # Your development dataset, for example dbt_bbaggins threads: 4 location: US # Must match the location of your BigQuery datasets ``` 4. Run the `debug` command from your project to confirm that you can successfully connect: ```shell $ dbt debug > Connection test: OK connection ok ```
### FAQs ## Perform your first dbt run Our sample project has some example models in it. We're going to check that we can run them to confirm everything is in order. 1. Enter the `run` command to build example models: ```shell dbt run ``` You should have an output that looks like this:
## Commit your changes Commit your changes so that the repository contains the latest code. 1. Link the GitHub repository you created to your dbt project by running the following commands in Terminal. Make sure you use the correct git URL for your repository, which you should have saved from step 5 in [Create a repository](/guides/manual-install?step=2). ```shell git init git branch -M main git add . git commit -m "Create a dbt project" git remote add origin https://github.com/USERNAME/dbt-tutorial.git git push -u origin main ``` 2. Return to your GitHub repository to verify your new files have been added. ### Build your first models Now that you set up your sample project, you can get to the fun part — [building models](/docs/build/sql-models)! In the next steps, you will take a sample query and turn it into a model in your dbt project. ## Checkout a new git branch Check out a new git branch to work on new code: 1. Create a new branch by using the `checkout` command and passing the `-b` flag: ```shell $ git checkout -b add-customers-model > Switched to a new branch `add-customer-model` ``` ## Build your first model If you'd like to use AI to build your first model, check out the build it with dbt Wizard in the next section. 1. Open your project in your favorite code editor. 2. Create a new SQL file in the `models` directory, named `models/customers.sql`. 3. Paste the following query into the `models/customers.sql` file. 4. From the command line, enter `dbt run`.
When you return to the BigQuery console, you can `select` from this model. ### FAQs ## Change the way your model is materialized ## Delete the example models ## Build models on top of other models 1. Create a new SQL file, `models/stg_customers.sql`, with the SQL from the `customers` CTE in our original query. 2. Create a second new SQL file, `models/stg_orders.sql`, with the SQL from the `orders` CTE in our original query.
```sql select id as customer_id, first_name, last_name from `dbt-tutorial`.jaffle_shop.customers ``` ```sql select id as order_id, user_id as customer_id, order_date, status from `dbt-tutorial`.jaffle_shop.orders ```
```sql select id as customer_id, first_name, last_name from jaffle_shop_customers ``` ```sql select id as order_id, user_id as customer_id, order_date, status from jaffle_shop_orders ```
```sql select id as customer_id, first_name, last_name from jaffle_shop.customers ``` ```sql select id as order_id, user_id as customer_id, order_date, status from jaffle_shop.orders ```
```sql select id as customer_id, first_name, last_name from raw.jaffle_shop.customers ``` ```sql select id as order_id, user_id as customer_id, order_date, status from raw.jaffle_shop.orders ```
3. Edit the SQL in your `models/customers.sql` file as follows: ```sql with customers as ( select * from {{ ref('stg_customers') }} ), orders as ( select * from {{ ref('stg_orders') }} ), customer_orders as ( select customer_id, min(order_date) as first_order_date, max(order_date) as most_recent_order_date, count(order_id) as number_of_orders from orders group by 1 ), final as ( select customers.customer_id, customers.first_name, customers.last_name, customer_orders.first_order_date, customer_orders.most_recent_order_date, coalesce(customer_orders.number_of_orders, 0) as number_of_orders from customers left join customer_orders using (customer_id) ) select * from final ``` 4. Execute `dbt run`. This time, when you performed a `dbt run`, separate views/tables were created for `stg_customers`, `stg_orders` and `customers`. dbt inferred the order to run these models. Because `customers` depends on `stg_customers` and `stg_orders`, dbt builds `customers` last. You do not need to explicitly define these dependencies. ### FAQs {#faq-2} ### Next steps You can also explore: * The `target` directory to see all of the compiled SQL. The `run` directory shows the create or replace table statements that are running, which are the select statements wrapped in the correct DDL. * The `logs` file to see how logs all of the action happening within your project. It shows the select statements that are running and other log output from when dbt runs. ## Add tests to your models ### Next steps ## Document your models Adding [documentation](/docs/build/documentation) to your project allows you to describe your models in rich detail, and share that information with your team. Here, we're going to add some basic documentation to our project. Update your `models/schema.yml` file to include some descriptions, such as those below. ```yaml version: 2 models: - name: customers description: One record per customer columns: - name: customer_id description: Primary key data_tests: - unique - not_null - name: first_order_date description: NULL when a customer has not yet placed an order. - name: stg_customers description: This model cleans up customer data columns: - name: customer_id description: Primary key data_tests: - unique - not_null - name: stg_orders description: This model cleans up order data columns: - name: order_id description: Primary key data_tests: - unique - not_null - name: status data_tests: - accepted_values: arguments: # available in v1.10.5 and higher. Older versions can set the as the top-level property. values: ['placed', 'shipped', 'completed', 'return_pending', 'returned'] - name: customer_id data_tests: - not_null - relationships: arguments: to: ref('stg_customers') field: customer_id ``` 1. Run `dbt docs generate` to compile the artifacts required for your projects static docs site. 2. Run `dbt docs serve` to launch the documentation in a local website. ### FAQs ## Commit updated changes You need to commit the changes you made to the project so that the repository has your latest code. 1. Add all your changes to git: `git add -A` 2. Commit your changes: `git commit -m "Add customers model, tests, docs"` 3. Push your changes to your repository: `git push -u origin add-customers-model` 4. Navigate to your repository, and open a pull request to merge the code into your master branch. ## Schedule a job We recommend using as the easiest and most reliable way to [deploy jobs](/docs/deploy/deployments) and automate your dbt project in production. For more info on how to get started, refer to [create and schedule jobs](/docs/deploy/deploy-jobs#create-and-schedule-jobs). To schedule jobs yourself with an orchestrator like Airflow, refer to the [dbt and Airflow](/blog/dbt-airflow-spiritual-alignment) blog post.