> For the complete documentation index, see [llms.txt](https://google-cloud-how-to.smarthive.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://google-cloud-how-to.smarthive.io/mapping-bucket-to-the-local-instance-on-google-cloud.md).

# Mapping bucket to the local instance on google cloud

You will need gcsfuse to map a bucket to your instance. Instructions to install on Linux and Mac are below. The github link is. <https://github.com/GoogleCloudPlatform/gcsfuse>

## Using gcsfuse

### Prerequisites

* Before invoking gcsfuse, you must have a GCS bucket that you want to mount. If your bucket doesn't yet exist, create one using the [Google Developers Console](https://console.developers.google.com/).
* Make sure [the Google Cloud Storage JSON API is enabled](https://cloud.google.com/storage/docs/json_api/#activating).
* GCS credentials are automatically loaded using [Google application default credentials](https://developers.google.com/identity/protocols/application-default-credentials#howtheywork), or a JSON key file can be specified explicitly using `--key-file`. If you haven't already done so, the easiest way to set up your credentials for testing is to run the [gcloud tool](https://cloud.google.com/sdk/gcloud/):

```
    gcloud auth login
```

See [mounting.md](https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/docs/mounting.md) for more information on credentials.

### Invoking gcsfuse

To mount a bucket using gcsfuse over an existing directory `/path/to/mount`, invoke it like this:

```
gcsfuse my-bucket /path/to/mount
```

**Important**: You should run gcsfuse as the user who will be using the file system, not as root. Do not use `sudo`.

The gcsfuse tool will exit successfully after mounting the file system. Unmount in the usual way for a fuse file system on your operating system:

```
umount /path/to/mount         # OS X
fusermount -u /path/to/mount  # Linux
```

If you are mounting a bucket that was populated with objects by some other means besides gcsfuse, you may be interested in the `--implicit-dirs` flag. See the notes in [semantics.md](https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/docs/semantics.md#implicit-directories) for more information.

## Installing gcsfuse

gcsfuse has been tested successfully with the following operating systems:

* Linux (minimum kernel version 3.10)
* OS X (minimum version 10.10.2)

It may or may not work correctly with other operating systems and older versions.

If you are running on [Google Compute Engine](https://cloud.google.com/compute/), it is recommended that you use one of the following images with which it has been tested (preferring the latest version when possible):

* `ubuntu-1804-lts`, `ubuntu-1604-lts`, and `ubuntu-1404-lts`
* `debian-8`, `debian-7`
* `centos-7`, `centos-6`
* `rhel-7`, `rhel-6`
* `sles-12`

## Linux

If you are running Linux on a 64-bit x86 machine and are happy to install pre-built binaries (i.e. you don't want to build from source), you need only ensure fuse is installed, then download and install the latest release package. The instructions vary by distribution.

### Ubuntu and Debian (latest releases)

The following instructions set up `apt-get` to see updates to gcsfuse, and are supported for the **bionic**, **artful**, **zesty**, **yakkety**, **xenial**, and **trusty** [releases](https://wiki.ubuntu.com/Releases) of Ubuntu, and the **jessie** and **stretch** [releases](https://www.debian.org/releases/) of Debian. (Run `lsb_release -c` to find your release codename.) Users of older releases should follow the instructions for [other distributions](broken://pages/-M4_EmhkG4dLnTbEi7m3#other-distributions) below.

1. Add the gcsfuse distribution URL as a package source and import its public key:

   ```
   export GCSFUSE_REPO=gcsfuse-`lsb_release -c -s`
   echo "deb http://packages.cloud.google.com/apt $GCSFUSE_REPO main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list
   curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
   ```
2. Update the list of packages available and install gcsfuse.

   ```
   sudo apt-get update
   sudo apt-get install gcsfuse
   ```
3. (**Ubuntu before wily only**) Add yourself to the `fuse` group, then log out and back in:

   ```
   sudo usermod -a -G fuse $USER
   exit
   ```

Future updates to gcsfuse can be installed in the usual way: `sudo apt-get update && sudo apt-get upgrade`.

### CentOS and Red Hat (latest releases)

The following instructions set up `yum` to see updates to gcsfuse, and work for CentOS 7 and RHEL 7. Users of older releases should follow the instructions for [other distributions](broken://pages/-M4_EmhkG4dLnTbEi7m3#other-distributions) below.

1. Configure the gcsfuse repo:

   ```
   sudo tee /etc/yum.repos.d/gcsfuse.repo > /dev/null <<EOF
   [gcsfuse]
   name=gcsfuse (packages.cloud.google.com)
   baseurl=https://packages.cloud.google.com/yum/repos/gcsfuse-el7-x86_64
   enabled=1
   gpgcheck=1
   repo_gpgcheck=1
   gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
          https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
   EOF
   ```
2. Make the system aware of the new repo:

   ```
   sudo yum update
   ```

   Be sure to answer "yes" to any questions about adding the GPG signing key.
3. Install gcsfuse:

   ```
   sudo yum install gcsfuse
   ```

   Be sure to answer "yes" to any questions about adding the GPG signing key.

Future updates to gcsfuse will automatically show up when updating with `yum`.

### SUSE

Ensure that dependencies are present:

```
sudo zypper install curl fuse
```

Download and install the latest release package:

```
curl -L -O https://github.com/GoogleCloudPlatform/gcsfuse/releases/download/v0.27.0/gcsfuse-0.27.0-1.x86_64.rpm
sudo rpm --install -p gcsfuse-0.27.0-1.x86_64.rpm
```

### Arch Linux

Available from [AUR](https://aur.archlinux.org/packages/gcsfuse/) and can be installed with any AUR helper.

```
pacaur -S gcsfuse
```

### Older releases and other distributions

Ensure that dependencies are present:

* Install [fuse](http://fuse.sourceforge.net/).
* Install [curl](http://curl.haxx.se/) (or use a different program for downloading below).

If you are on a distribution that uses `.rpm` files for package management:

```
curl -L -O https://github.com/GoogleCloudPlatform/gcsfuse/releases/download/v0.27.0/gcsfuse-0.27.0-1.x86_64.rpm
sudo rpm --install -p gcsfuse-0.27.0-1.x86_64.rpm
```

Or one that uses `.deb` files:

```
curl -L -O https://github.com/GoogleCloudPlatform/gcsfuse/releases/download/v0.27.0/gcsfuse_0.27.0_amd64.deb
sudo dpkg --install gcsfuse_0.27.0_amd64.deb
```

On some systems it may be necessary to add the your user account to the `fuse` group in order to have permission to run `fusermount` (don't forget to log out and back in afterward for the group membership change to take effect):

```
sudo usermod -a -G fuse $USER
exit
```

Old versions of Debian contain a [bug](http://superuser.com/a/800016/429161) that causes `/dev/fuse` to repeatedly lose its permission settings. If you find that you receive permissions errors when mounting, even after running the `usermod` instruction above and logging out and back in, you may need to fix the permissions:

```
sudo chmod g+rw /dev/fuse
sudo chgrp fuse /dev/fuse
```

## OS X

First, handle prerequisites:

* Install [osxfuse](https://osxfuse.github.io/).
* Install the [homebrew](http://brew.sh/) package manager.

Afterward, gcsfuse can be installed with `brew`:

```
brew install gcsfuse
sudo ln -s /usr/local/sbin/mount_gcsfuse /sbin  # For mount(8) support
```

The second command is only necessary if you want to use gcsfuse with the `mount` command or in your `/etc/fstab` file, as opposed to calling `gcsfuse` directly.

In the future gcsfuse can be updated in the usual way for homebrew packages:

```
brew update && brew upgrade
```

## Building from source

Prerequisites:

* A working [Go](http://tip.golang.org/doc/install/source) installation at least as new as [commit 183cc0c](https://github.com/golang/go/commit/183cc0c). See [Installing Go from source](http://golang.org/doc/code.html).
* Fuse. See the instructions for the binary release above.
* Git. This is probably available as `git` in your package manager.

Because we use the [Go 1.5 vendoring support](https://github.com/golang/go/commit/183cc0c), you must ensure that the appropriate variable is set in your environment:

```
export GO15VENDOREXPERIMENT=1
```

To install or update gcsfuse, run:

```
go get -u github.com/googlecloudplatform/gcsfuse
```

This will fetch the gcsfuse sources to `$GOPATH/src/github.com/googlecloudplatform/gcsfuse`, build them, and install a binary named `gcsfuse` to `$GOPATH/bin`.

## Unmount a bucket

```
fusermount -u /home/shared/local_folder/
```
