> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Compiling and installing the application

> Learn to compile, install, and run your Go application with step-by-step instructions for building code and configuring your environment.

In this lesson, you'll learn how to compile, install, and run your Go application seamlessly. Follow these steps to build your code, create an executable, and configure your environment so the application can be run from anywhere.

## Compiling the Application

Begin by opening your terminal and navigating to your module directory. Compile your Go code into an executable by executing the following command:

```bash theme={null}
go build
```

After running the command, an executable file will be generated in your current working directory. On Linux or macOS, run the executable using:

```bash theme={null}
./cryptit
```

On Windows systems, ensure you include the `.exe` extension when executing the file.

When you run the executable, you should see output similar to:

```bash theme={null}
> go build
> ./cryptit
Nrghnorxg
Kodekloud
```

<Callout icon="lightbulb" color="#1CB2FE">
  If your current shell prompt is not within the directory that contains the executable, you will need to provide the full path to run it. For instance, running `./cryptit` from your home directory might result in an error like:

  ```bash theme={null}
  zsh: no such file or directory: ./cryptit
  ```

  In this case, specify the full path to the executable.
</Callout>

## Installing the Application with Go Install

To enable running your application from any directory, install the binary into a directory that is part of your system's PATH. Follow these steps:

1. **Determine your Go installation path (GOPATH):**\
   Locate where your Go binaries are stored.

2. **Update your PATH environment variable:**\
   On Linux or macOS, add your GOPATH's `bin` directory to the PATH by running:

   ```bash theme={null}
   export PATH=$PATH:/Users/priyanka/go/bin
   ```

   On Windows, you can update the PATH using the `set` command or by modifying your system environment variables.

3. **Install the Application:**\
   Go back to your module directory and install the application with:

   ```bash theme={null}
   go install
   ```

   This command compiles the package and places the binary in the `bin` directory under your GOPATH.

4. **Verify the Installation:**\
   Navigate to your GOPATH's `bin` directory and list its contents:

   ```bash theme={null}
   cd ~/go/bin
   ls
   ```

   You should see the binary (e.g., `cryptit`) listed. Now, you can run your application from any location by simply typing:

   ```bash theme={null}
   cryptit
   ```

   This will display the same expected output as before.

## Sample Application Code

Below is an example of the Go code used in this lesson to demonstrate encryption and decryption functionalities:

```go theme={null}
package main

import (
    "fmt"
    "encrypt"
    "decrypt"
)

func main() {
    encryptedStr := encrypt.Nimbus("Kodekloud")
    fmt.Println(encryptedStr)
    fmt.Println(decrypt.Nimbus(encryptedStr))
}
```

That's it for this lesson. We hope these instructions help you successfully compile and install your Go application. Happy coding, and see you in the next tutorial!

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/advanced-golang/module/6ce7d245-515e-428d-9672-915e49a8ebd6/lesson/ab3c3730-e7c8-4cb6-90d6-ffefac74a7f1" />
</CardGroup>
