4

I'm following the instructions in https://golang.org/doc/code.html#Library and trying to use Goland. I'm surprised though that I can't find a fast way to install the library I'm writing. According to the tutorial, you should use install to install your code in the pkg or bin folders, yet I can't find a way to do this in Goland other than writing it in the console. What am I missing?

uzilan
  • 2,554
  • 2
  • 31
  • 46
  • 1
    I'm not sure what you're asking. Are you trying to install a program you've written? Or are you trying to install a library dependency that your program needs? – Jonathan Hall Jan 28 '18 at 11:59
  • A library I'm writing – uzilan Jan 28 '18 at 12:01
  • That doesn't really provide any clarity. You don't typically "install libraries" in Go, as Go is statically linked. – Jonathan Hall Jan 28 '18 at 12:02
  • Run `go get ./...` before running the build command. – Alex Efimov Jan 28 '18 at 12:04
  • @AlexEfimov: `go install` is not normally used or needed for libraries. – Jonathan Hall Jan 28 '18 at 12:05
  • I meant `get`, sorry about that. – Alex Efimov Jan 28 '18 at 12:06
  • Ok thanks. I'm just following the tutorial and since they used it there I thought one would install libraries frequently. Thanks for clearing that up! – uzilan Jan 28 '18 at 12:08
  • I don't understand, are you asking about the Go programming language? Or GoLand, the IDE from JetBrains dedicated for Go https://www.jetbrains.com/go/ ? – dlsniper Jan 28 '18 at 12:10
  • That depends on what you mean by "install libraries". If you mean, fetch third-party library dependencies, yes, that's common. `go get` does that. Goland may provide some interface for the same, I have no idea. If you mean something with `go install`, no--that is used for installing the output of a program you've written. Dynamically linked languages have an equivalent for libraries--installing the shared library object files, DLLs, etc. Go has no such step, typically. – Jonathan Hall Jan 28 '18 at 12:11
  • It's starting to sound like you've written a library, and now want to use it in other projects. If that is the case, there is nothing special going on here. You just install that dependency the same way you install any other dependency. And if Goland has a shortcut for installing deps, it should work in this case, too. – Jonathan Hall Jan 28 '18 at 12:12
  • Ok, sorry if I wasn't clear. Yes, I'm writing my own library and am using the install command to make it available to other programs. Now, since I thought this would be a common thing to do, I expected that Jetbrains own Go IDE Goland to have a simple way to allow me to do that, rather that using the command line. Thats why I was asking if Goland has a simple way to install libraries, by which I ment my own. Hope this is clear enough? – uzilan Jan 28 '18 at 12:19
  • Yes, it's clear enough now. I've added a complete response that covers both third-party libraries as well as libraries present on your system. – dlsniper Jan 28 '18 at 13:04

1 Answers1

10

There are two ways to import Go packages using GoLand:

  1. copy-paste the code that needs the package into the IDE and then on the import declaration use Show Intention to see the list of actions available and choose the first one, go get -t <package-name>/...
  2. copy the URL of the Github repository into your clipboard, switch to the IDE and use the pop-up to run go get on the package. The pop-up disappears after a few seconds.

I've attached the image which shows these options. import packages in GoLand

This will download libraries in the correct GOPATH directory and run go install as part of the go get action.

As for installing the libraries that you are developing in GOPATH/pkg, there is no need for that, as soon as you run any configuration from the IDE, be it an application or a test that depend on those libraries, the IDE will install those libraries as well.

dlsniper
  • 7,188
  • 1
  • 35
  • 44