# Dfx Error: Canister cannot be installed because the canister is not empty

**URL:** <https://forum.dfinity.org/t/dfx-error-canister-cannot-be-installed-because-the-canister-is-not-empty/2051>\
**Category:** Developers\
**Created:** [February 26, 2021, 9:22pm UTC](https://forum.dfinity.org/t/dfx-error-canister-cannot-be-installed-because-the-canister-is-not-empty/2051 "2021-02-26T21:22:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![evanmcfarland](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/evanmcfarland/32/1744_2.png) [@evanmcfarland](https://forum.dfinity.org/u/evanmcfarland)\
**Post date:** [February 26, 2021, 9:22pm UTC](https://forum.dfinity.org/t/dfx-error-canister-cannot-be-installed-because-the-canister-is-not-empty/2051/1 "2021-02-26T21:22:23Z")

</div>

I’m a new developer struggling with dfx. This is one of the problems I’m running into when doing “Hakin’ on The Internet Computer ep.1.” I’m using a linux machine and it should already have all the recommended packages installed.

Here’s the command line process and where I get stuck:

`dfx new phonebook`  
-The canister files were never made and errors with dfx build lead me to this  
`dfx canister create phonebook_assets`  
`dfx canister create phonebook`  
`dfx canister install phonebook`  
`dfx canister install --all`  
-The Replica returned an error: code 5, message: “Canister X cannot be installed because the canister is not empty. Try installing with mode=‘reinstall’ instead.”

Why does this happen, will this repeat with every change to the main.mo file, and how do I fix it?

By the way, the canister does work when I call it;  
`dfx canister call phonebook greet world`  
(“Hello, world!”)  
But I can’t get any updates to the code to take.

Any help much appreciated.

---

<div class="post-metadata">

**Author:** ![Steve](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@Steve](https://forum.dfinity.org/u/Steve)\
**Post date:** [February 26, 2021, 9:25pm UTC](https://forum.dfinity.org/t/dfx-error-canister-cannot-be-installed-because-the-canister-is-not-empty/2051/2 "2021-02-26T21:25:03Z")

</div>

try

dfx deploy

or

dfx canister install --all --mode upgrade

or  
dfx canister install --all --mode=upgrade

can’t remember if you need the =

---

<div class="post-metadata">

**Author:** ![rckprtr](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rckprtr/32/809_2.png) [@rckprtr](https://forum.dfinity.org/u/rckprtr)\
**Post date:** [February 27, 2021, 12:55am UTC](https://forum.dfinity.org/t/dfx-error-canister-cannot-be-installed-because-the-canister-is-not-empty/2051/3 "2021-02-27T00:55:17Z")

</div>

> [@Steve](#):
>
> dfx canister install --all --mode=upgrade

`dfx canister install --all --mode reinstall`

---

<div class="post-metadata">

**Author:** ![lsgunn](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lsgunn/32/124_2.png) [@lsgunn](https://forum.dfinity.org/u/lsgunn)\
**Post date:** [March 12, 2021, 4:36pm UTC](https://forum.dfinity.org/t/dfx-error-canister-cannot-be-installed-because-the-canister-is-not-empty/2051/4 "2021-03-12T16:36:21Z")

</div>

Looks like you might be missing this step:  
`dfx build`

You also might want to check out [sdk.dfinity.org/docs/quickstart/quickstart-local.html](http://sdk.dfinity.org/docs/quickstart/quickstart-local.html)

---

<div class="post-metadata">

**Author:** ![zire](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zire/32/7873_2.png) [@zire](https://forum.dfinity.org/u/zire)\
**Post date:** [April 20, 2021, 3:50pm UTC](https://forum.dfinity.org/t/dfx-error-canister-cannot-be-installed-because-the-canister-is-not-empty/2051/5 "2021-04-20T15:50:28Z")

</div>

> [@rckprtr](#):
>
> dfx canister install --all --mode reinstall

Thanks. I ran into the same “not empty” issue and this command fixed it.
