# I can't use packages

**URL:** <https://forum.golangbridge.org/t/i-cant-use-packages/28635>\
**Category:** Code Review\
**Created:** [August 28, 2022, 4:24pm UTC](https://forum.golangbridge.org/t/i-cant-use-packages/28635 "2022-08-28T16:24:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaenmo](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/jaenmo/32/11931_2.png) [@jaenmo](https://forum.golangbridge.org/u/jaenmo)\
**Post date:** [August 28, 2022, 4:24pm UTC](https://forum.golangbridge.org/t/i-cant-use-packages/28635/1 "2022-08-28T16:24:55Z")

</div>

I’m having problems to use packages. I a following literally the steps I find online, but I have an error message.

I have this package in GOPATH:  
go/src/greet/day.go

```auto
package greet

var morning = "Good morning"
var Morning = "hey" + morning

```

I want to import it in my code:  
go/src/app/entry.go

```auto
package main

import ("fmt"
        "greet")

func main(){
    fmt.Println(greet.Morning)
}

```

When I run entry.go, I receive this message: entry.go:4:3: package greet is not in GOROOT (/usr/local/go/src/greet)

Does anybody how to fix it?

Thank you.

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/nobbz/32/3096_2.png) [@NobbZ](https://forum.golangbridge.org/u/NobbZ)\
**Post date:** [August 28, 2022, 4:49pm UTC](https://forum.golangbridge.org/t/i-cant-use-packages/28635/2 "2022-08-28T16:49:56Z")

</div>

Modern go does not rely on `GOPATH` anymore.

Please use proper modules with an appropriate module path.

---

<div class="post-metadata">

**Author:** ![Ien\_Conor](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/ien_conor/32/13153_2.png) [@Ien\_Conor](https://forum.golangbridge.org/u/Ien_Conor)\
**Post date:** [April 13, 2023, 1:19pm UTC](https://forum.golangbridge.org/t/i-cant-use-packages/28635/3 "2023-04-13T13:19:13Z")

</div>

Thanks a lot for help!

---

<div class="post-metadata">

**Author:** ![alex99](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@alex99](https://forum.golangbridge.org/u/alex99)\
**Post date:** [April 30, 2023, 8:53am UTC](https://forum.golangbridge.org/t/i-cant-use-packages/28635/5 "2023-04-30T08:53:17Z")

</div>

In order to use a package, Go has to know where the package is. There are two ways to do this in your example. But first, move the directories outside of $GOPATH.

If you want “greet” to be a library that you can use and maintain as a separate project, independently of “app”, then you have two modules. If “greet” and “app” are in the same parent directory, then:

```auto
cd greet
go mod init greet
go mod tidy
cd ../app
go mod init app

```

edit app/go.mod and add this line:

`replace greet => ../greet`

then:

```auto
go mod tidy
go build entry.go

```

“go mod init” creates a go.mod file, that you can also create or edit by hand.  
“go mod tidy” creates a go.sum file.

It doesn’t matter what you name the app module, if you don’t import it anywhere else. You could have named it “main” (go mod init main).

The situation is simpler if you put greet/ and app/ in the same module. Move app/ inside greet/, so that you have the file structure:

greet/day.go  
greet/app/entry.go

First, remove any go.mod, go.sum files from the previous step.  
Then:

```auto
cd greet
go mod init greet
go mod tidy
cd ./app
go build entry.go

```

In both cases you have two packages, but in the first case you have two modules, while in the second case you have one module.
