오늘도 한 뼘 더

[Golang] package ... is not in GOROOT 에러 해결하기 본문

Study/Go

[Golang] package ... is not in GOROOT 에러 해결하기

나른한댕댕이🐶 2022. 8. 26. 11:37
728x90
반응형

  # 문제  

Golang 프로젝트를 새로 만들고 다음 코드에 대해 main.go를 실행하는 중에 다음과 같은 에러가 발생했다.

 package main

 import (
 	 "fmt"
 )

 func main() {
	 fmt.Println("Hello")
 }

 

  • 에러 메시지

 

  # 해결방법  

go에서 제공하는 문서를 참고하여 진행하였다. 

https://go.dev/blog/using-go-modules

 

Using Go Modules - The Go Programming Language

Using Go Modules Tyler Bui-Palsulich and Eno Compton 19 March 2019 Introduction This post is part 1 in a series. Note: For documentation on managing dependencies with modules, see Managing dependencies. Go 1.11 and 1.12 include preliminary support for modu

go.dev

 

go module 추가

실행하고자 하는 프로젝트에 모듈을 추가하는 명령어를 실행한다. 

 go mod init

실행을 하면 다음과 같이 go.mod가 만들어진다는 메시지가 뜬다.

 

프로젝트에 go.mod가 뜬 걸 확인할 수 있다.

 

다시 main.go를 실행하면 정상적으로 작동이 된다. 

728x90
반응형
Comments