# Can not upgrade a canister's code

**URL:** <https://forum.dfinity.org/t/can-not-upgrade-a-canisters-code/34295>\
**Category:** Developers\
**Tags:** Discussing\
**Created:** [August 19, 2024, 3:32pm UTC](https://forum.dfinity.org/t/can-not-upgrade-a-canisters-code/34295 "2024-08-19T15:32:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![readygo67](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/readygo67/32/13870_2.png) [@readygo67](https://forum.dfinity.org/u/readygo67)\
**Post date:** [August 19, 2024, 3:32pm UTC](https://forum.dfinity.org/t/can-not-upgrade-a-canisters-code/34295/1 "2024-08-19T15:32:15Z")

</div>

Steps:

1. deploy [examples/rust/basic\_bitcoin at master · dfinity/examples · GitHub](https://github.com/dfinity/examples/tree/master/rust/basic_bitcoin) on ICP
2. Add the following function in,

```auto
#[ic_cdk_macros::query]
fn greet(name: String) -> String {
    format!("Hello, {}!", name)
}

```

1. run “dfx build”
2. run “dfx canister install basic\_bitcoin --network ic --mode upgrade”
3. it always reports “Module hashxxx is already installed”.

My question is how to upgrade a canister code?

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [August 19, 2024, 3:42pm UTC](https://forum.dfinity.org/t/can-not-upgrade-a-canisters-code/34295/2 "2024-08-19T15:42:25Z")

</div>

> [@readygo67](#):
>
> it always reports “Module hashxxx is already installed”

Because there is no changes, the IC tells you that no upgrade is required - “hash of the wasm is the same as the once already installed”. If you modify the code, build and deploy again, it should work out.

---

<div class="post-metadata">

**Author:** ![readygo67](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/readygo67/32/13870_2.png) [@readygo67](https://forum.dfinity.org/u/readygo67)\
**Post date:** [August 19, 2024, 3:45pm UTC](https://forum.dfinity.org/t/can-not-upgrade-a-canisters-code/34295/3 "2024-08-19T15:45:01Z")

</div>

I add greet() function in to basic\_bitcoin’s lib.rs, and build again. I think the wasm is changed.

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [August 19, 2024, 3:59pm UTC](https://forum.dfinity.org/t/can-not-upgrade-a-canisters-code/34295/4 "2024-08-19T15:59:40Z")

</div>

Maybe it was not build? Either way, don’t really know another reason to “Module hashxxx is already installed” than trying to install the same version of the code.

---

<div class="post-metadata">

**Author:** ![readygo67](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/readygo67/32/13870_2.png) [@readygo67](https://forum.dfinity.org/u/readygo67)\
**Post date:** [August 19, 2024, 4:15pm UTC](https://forum.dfinity.org/t/can-not-upgrade-a-canisters-code/34295/5 "2024-08-19T16:15:44Z")

</div>

After several times test, I believe the code is not rebuilt.  
Another interesting thing, after rebuild

1. if I call “dfx canister install basic\_bitcoin --network ic --mode upgrade” it reports same code.
2. if I call “dfx deploy basic\_bitcoin --network ic”, it can upgrade the code on ICP.

What’s the difference between these 2 commands in upgrading canister?

---

<div class="post-metadata">

**Author:** ![rbole](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rbole/32/1334_2.png) [@rbole](https://forum.dfinity.org/u/rbole)\
**Post date:** [August 20, 2024, 5:28am UTC](https://forum.dfinity.org/t/can-not-upgrade-a-canisters-code/34295/6 "2024-08-20T05:28:10Z")

</div>

- dfx install is installing a pre build wasm code.
- dfx deploy is a command which includes a couple of commands (create canisters if needed, build the wasm and installs the wasm into the canister.

You can try dfx install —mode reinstall if you want reinstall your code completely.

> **[dfx deploy | Internet Computer](https://internetcomputer.org/docs/current/developer-docs/developer-tools/cli-tools/cli-reference/dfx-deploy)**
>
> Use the dfx deploy command to register, build, and deploy a dapp on the local canister execution environment, on the IC or on a specified testnet. By default, all canisters defined in the project dfx.json configuration file are deployed.

vs

> **[dfx canister | Internet Computer](https://internetcomputer.org/docs/current/developer-docs/developer-tools/cli-tools/cli-reference/dfx-canister#dfx-canister-install)**
>
> Use the dfx canister command with options and subcommands to manage canister operations and interaction with the

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [August 20, 2024, 12:52pm UTC](https://forum.dfinity.org/t/can-not-upgrade-a-canisters-code/34295/7 "2024-08-20T12:52:08Z")

</div>

> [@readygo67](#):
>
> - run “dfx build”
> - run “dfx canister install basic\_bitcoin --network ic --mode upgrade”

`dfx build` is shorthand for `dfx build --network local`. It does not affect the wasm built for `--network ic`. Therefore `dfx canister install --network ic` will not see any updates to the wasm

Either use `dfx build --network ic` (or shorthand `dfx build --ic`) before `dfx canister install` or use `dfx deploy --ic`, which will build and install automatically
