[bash:xxx:command not found problem, encountered on the jetson-orin-nx of Nvidia > > > One of the solutions]

1 Overview

I recently started to learn NVIDIA's industrial control board. As a novice, there are still many differences to understand, but part of the linux system it uses is a bit like playing with Raspberry Pi. Although I haven't played with Raspberry Pi 6, I have always held a novice mentality.

The jetson-orin-nx industrial control board I bought at the beginning was borrowed by others and used for a period of time. After getting it back, there was a problem. It took two days to solve it. It can be regarded as part of self-study, so record this.

2. Experimental environment

For the first time, please use the software and hardware information provided here.
Hardware Information: Jetson Orin nx
Software Version: 5.10.104-tegra #1 SMP PREEMPT Sun Mar 19 07:55:28 PDT 2023 aarch64 aarch64 aarch64 GNU/Linux
insert image description here

3. Problem description: bash: xxx: command not found problem

When I got it back, I tried to type a normal command in the terminal, such as "ls to view the directory, pwd, or cd", and it reported bash:xxx:command not found.
insert image description here

Then search the Internet for most of the solutions, enter a command, as follows, and simply configure the environment variables.

export PATH=/bin:/usr/bin:$PATH

But in fact, the indicator does not cure the root cause. Once it is restarted, or a new terminal is opened, it will not work again.
insert image description here

4. My efforts

The first way: add command mode

As described in the above problem, it is the way to add commands, but this does not last long. It is very troublesome to enter every time you restart or open a new terminal.

export PATH=/bin:/usr/bin:$PATH

The second way: use the echo $PATH command to view environment variables

By using the command

echo $PATH

I found that the returned environment variable is: /usr/local/cuda-11.4,
which is obviously wrong, indicating that someone else has touched this environment variable.
insert image description here
So the idea becomes, where can this environment variable be set.

So what should be the default environment variable, as shown in the figure below, on another nx, as shown below.
insert image description here
It is assisted as follows. Here is the guide for most of the situation, and I also have some concerns with the board. I use jetson, which is the related industrial computer of Nvidia, and have not checked other boards.

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

The third way: view and compare the contents of the /etc/profile file

There is information on the Internet that the environment variable can be increased by modifying the content of the following customs clearance, or adding the content of the environment variable. The more I found another industrial control board, compared the content, and found that there was no difference. No changes have been made. The specific content is as follows,
insert image description here

The fourth way: Rewrite the contents of the /etc/bash.bashrc file

Later, according to the online instructions, it was said that the internal content of ~/.bashrc should be changed. I once thought it was a file in this directory under /etc/bash.bashrc, and the rewriting was completed as shown in the figure below.
insert image description here

After adding the content of this file, it is found that

文件
/etc/bash.bashrc
加入内容
export PATH=$PATH:/usr/local/bin
export PATH=$PATH:/usr/local/sbin
export PATH=$PATH:/usr/sbin
export PATH=$PATH:/usr/bin
export PATH=$PATH:sbin
export PATH=$PATH:bin

Run source /etc/bash.bashrc, the interface turns white, but it still doesn’t work when you open a new terminal, which means that the problem is not here.
insert image description here

Explain that the problem is no longer here.

5. Solution

Later, I thought that the == " /.bashrc"== file may not refer to the "/etc/bash.bashrc" file. I thought that /.bashrc generally refers to files ending with "bashrc", and there is such a "~/.bashrc" file.
So, look at this file directly, the command is as follows.

cat ~/.bashrc

insert image description here
You can see that it is the above picture, which is caused by the added content. Others are not available, just comment them out.

Later, I checked and used the history command, and found that this file was moved at the beginning.
insert image description here

6. Solutions

Sometimes it’s like this, you encounter a problem and solve it, it’s best not to let it go like this, you need to understand why it can be solved, and understand it deeper.
I conclude that if you encounter this kind of problem at present, and according to the online information, there are generally several ways.

1. The command is not installed

Command not installed: The command entered is not installed on the system, and this error message will appear. The command needs to be installed before it can be used in the terminal. To put it bluntly, there is no such command, you need to use apt-get, or other commands to install it.

2. The environment variable configuration is incorrect

The environment variable configuration is incorrect: the path where the command is located is not in the PATH environment variable: the entered command has been installed on the system, but the terminal cannot find the path of the command, and this error prompt will also appear. The command needs to be added to the PATH environment variable. At present, just like the above solution, add it to the ~/.bashrc file. Of course, there are still other files mentioned on the Internet, such as /etc/profile files, etc.

3. Spelling mistakes

Command name spelling error: If the input command name is spelled wrong, this error message will also appear. You need to check whether the spelling of the entered command name is correct, but if you try a few more commands and it doesn’t work, it is generally the case similar to this article, and the entire environment variable has been changed.

7. Details

As a novice, there are still many things I don't understand, and these need to be supplemented by finding information.
(1) Under Linux, what is the difference between the ~/.bashrc file and the bash.bashrc file? This question asked chatgpt for reference

~/.bashrc 文件和/etc/bash.bashrc 文件都是 Bash shell 的配置文件,但它们的作用和范围有所不同。

~/.bashrc 文件是每个用户的个人 Bash shell 配置文件,通常位于用户的家目录下。该文件包含用户自定义的 shell 配置,例如别名、环境变量、命令别名等。当用户登录时,Bash shell 会自动加载该文件。

/etc/bash.bashrc 文件是全局 Bash shell 配置文件,适用于所有用户和所有 Bash shell。该文件包含系统管理员定义的全局 Bash shell 配置,例如全局别名、全局环境变量等。当用户登录时,Bash shell 会自动加载该文件。

因此,~/.bashrc 文件和/etc/bash.bashrc 文件的区别在于它们的作用范围。~/.bashrc 文件是每个用户的个人配置文件,/etc/bash.bashrc 文件是全局配置文件。

需要注意的是,不同的 Linux 发行版可能会有所不同。在某些系统上,可能没有 /etc/bash.bashrc 文件,或者该文件被命名为 bashrc 或其他名称。如果您有疑问,请参考您所使用的系统的文档。

(2) What is the use of environment variables, or what role does it play in Linux, and what to do, also asked chatgpt for reference

环境变量是一组在操作系统中用来控制系统行为的变量。在 Linux 中,环境变量被广泛使用,它们可以控制系统的行为、设置用户的配置和提供有用的信息。

以下是环境变量在 Linux 中的主要用途:

控制系统行为:环境变量可以用来控制系统的行为。例如,PATH 环境变量指定了系统在哪些目录中查找可执行文件,LANG 环境变量指定了系统使用的语言环境。

设置用户的配置:环境变量可以用来设置用户的个人配置。例如,HOME 环境变量指定了当前用户的家目录,USER 环境变量指定了当前登录用户的用户名。

传递信息:环境变量可以用来传递信息。例如,在 Makefile 中,可以使用环境变量来传递编译器选项和链接器选项。

程序交互:某些程序使用环境变量来进行交互。例如,LESS 环境变量指定了 less 命令在显示文本时的选项。

在 Linux 中,环境变量可以使用 export 命令设置和修改,可以使用 echo 命令查看。通常,环境变量的名称使用大写字母表示,例如 PATH、HOME 等。

总之,环境变量是 Linux 中非常重要的概念,它们可以控制系统行为、设置用户配置、传递信息和支持程序交互。

(3) Open a new terminal and report an error, because a match is wrongly typed, where the "#" represents a comment, but it is typed as "$".
insert image description here

8. Summary

Let's accumulate a little bit, and if you don't accumulate silicon steps, you can go thousands of miles.

Guess you like

Origin blog.csdn.net/qq_22146161/article/details/131689238