> For the complete documentation index, see [llms.txt](https://kajirikajiri.gitbook.io/gitbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kajirikajiri.gitbook.io/gitbook/nodenv-global-not-working.md).

# nodenv global not working

nodeの最新版が使いたかった。なので、globalに設定した

```
nodenv global 14.2.0
```

しかし、かわらない

```
$ node
Welcome to Node.js v13.12.0.
```

次は、localに設定してみる

```
nodenv local 14.2.0
```

これはうまくいったが `.node-version` というファイルが発生してしまう

不要なので、原因を探した

## 原因

.node-versionというファイルが親ディレクトリに存在していたのが原因だった

```
$ node
nodenv: version `13.12.0' is not installed (set by /root/.node-version)
```

これについては、nodenvに情報があった(<https://github.com/nodenv/nodenv#choosing-the-node-version>)

> #### ノードバージョンの選択(翻訳しました)
>
> シムを実行すると、nodenvは次のソースからこの順序で読み取ることにより、使用するノードのバージョンを決定します。
>
> 1. `NODENV_VERSION`環境変数、指定された場合。[`nodenv shell`](https://github.com/nodenv/nodenv#nodenv-shell)コマンドを使用して、現在のシェルセッションでこの環境変数を設定できます。
> 2. `.node-version`ファイルシステムのルートに到達するまで、実行中のスクリプトのディレクトリとその各親ディレクトリを検索して見つかった最初のファイル。
> 3. `.node-version`ファイルシステムのルートに到達するまで、現在の作業ディレクトリとその各親ディレクトリを検索して見つかった最初のファイル。コマンドを`.node-version`使用して、現在の作業ディレクトリにあるファイルを変更できます[`nodenv local`](https://github.com/nodenv/nodenv#nodenv-local)。
> 4. グローバル`~/.nodenv/version`ファイル。[`nodenv global`](https://github.com/nodenv/nodenv#nodenv-global)コマンドを使用して、このファイルを変更できます。グローバルバージョンファイルが存在しない場合、nodenvは「システム」ノードを使用することを想定しています。つまり、nodenvがパスになかった場合に実行されるバージョンです。

上記2,3にあるように、各親ディレクトリを検索して見つかった最初のファイルを設定する。

なので、/root/にあった、`.node-version` が参照されてしまった。

こいつを削除したら、nodeversionが想定通りになった。

```
 rm /root/.node-version
```

## 過程

nodeのバージョンが想定通りにならない

nodenv globalで設定。失敗

nodenv localで設定。成功。しかし、`.node-version`が作業ディレクトリに作成される

nodenvでinstall済みのversionを削除

nodeを実行するとエラーが発生

```
nodenv: version `13.12.0' is not installed (set by /root/.node-version)
```

いろいろ調べた結果いらないと判断。削除

平和になった


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://kajirikajiri.gitbook.io/gitbook/nodenv-global-not-working.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
