How to Solve Error Message on executing go package github.com: mkdir /usr/bin/src: permission denied

Posted on

Introduction

This article has a specific content. It will show how to solve an error message upon executing the ‘go’ command. The error message exists as follows :

user@hostname:~$ go get -u github.com/xxxxxxx/xxxxxxxx 
package github.com/xxxxxxx/xxxxxxxx : mkdir /usr/bin/src: permission denied
user@hostname:~$

Basically, the command above is a command for cloning specific directory in the github.com where the location exists for an example in github.com/xxxxxxx/xxxxxxxx.

The problem is the ‘go’ command exist in ‘/usr/bin’. By default, in an Ubuntu Linux operating system distribution, executing a command without any full path has several considerations. Normally, the operating system will search the command in the list path inside the file in the /etc/environment. For an example, below is the content of the file :

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

So, operating system will search the ‘go’ command in all of the path in the list above. Fortunately, the ‘go’ command exists in ‘/usr/bin’. There is an error message upon executing the above command for cloning a package or directory from github.com. It is a ‘permission denied’ error message because the execution of the ‘go’ command by a normal user doesn’t have a write permission in the ‘/usr/bin’ path.

The solution to solve the error

Fortunately, there is a solution for solving the problem. It is possible to change the path for cloning the package or directory from github.com. Below are the steps for achieving it :

1. Just try to define the environment variable with the name of ‘GOPATH’ in the environment variable file. Normally, it exists in the .bashrc file of the home user directory. For an example, if there is a user with the name of ‘user’, the location of the file exists in ‘/home/user/.bashrc’. The following is an example of the ‘GOPATH’ definition :

export GOPATH=/home/user/go
export PATH=$PATH:$GOPATH

2. Next step, don’t forget to execute the following to apply the change. Type the following command :

user@hostname:~$ source /home/user/.bashrc
user@hostname:~$

3. Finally, try to execute the command above. Afterwards, the cloning result of the package or directory is available in the ‘/home/user/go’ folder.

Leave a Reply